Add write_timeout policy configuration option#7499
Merged
neilalexander merged 2 commits intomainfrom Oct 31, 2025
Merged
Conversation
… leafnodes Signed-off-by: Neil Twigg <neil@nats.io>
derekcollison
approved these changes
Oct 31, 2025
server/client.go
Outdated
| fsp int32 // Flush signals that are pending per producer from readLoop's pcd. | ||
| sg *sync.Cond // To signal writeLoop that there is data to flush. | ||
| wdl time.Duration // Snapshot of write deadline. | ||
| wtp WriteTimeoutPolicy // What do we do on a write timeout? |
Member
There was a problem hiding this comment.
Can we store this once in the server struct?
Member
Author
There was a problem hiding this comment.
Earlier versions of this code did have them in the server struct but the switch was slower than having it per-client, although I have noticed that I can make the WriteTimeoutPolicy a uint8 instead and modify the placement in the outbound struct, and then it actually takes up no more extra space due to existing alignment, so I'll do that.
Member
Author
There was a problem hiding this comment.
main branch:
// client.go:330 | Size: 112
type outbound struct {
nb net.Buffers ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
wnb net.Buffers ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
pb int64 ■ ■ ■ ■ ■ ■ ■ ■
fsp int32 ■ ■ ■ ■ □ □ □ □
sg *sync.Cond ■ ■ ■ ■ ■ ■ ■ ■
wdl time.Duration ■ ■ ■ ■ ■ ■ ■ ■
mp int64 ■ ■ ■ ■ ■ ■ ■ ■
lft time.Duration ■ ■ ■ ■ ■ ■ ■ ■
stc chan struct{} ■ ■ ■ ■ ■ ■ ■ ■
cw *s2.Writer ■ ■ ■ ■ ■ ■ ■ ■
}
After this fix, so same amount of space consumed overall:
// client.go:350 | Size: 112
type outbound struct {
nb net.Buffers ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
wnb net.Buffers ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■ ■ ■
pb int64 ■ ■ ■ ■ ■ ■ ■ ■
fsp int32 ■ ■ ■ ■
wtp WriteTimeoutPolicy ■ □ □ □
sg *sync.Cond ■ ■ ■ ■ ■ ■ ■ ■
wdl time.Duration ■ ■ ■ ■ ■ ■ ■ ■
mp int64 ■ ■ ■ ■ ■ ■ ■ ■
lft time.Duration ■ ■ ■ ■ ■ ■ ■ ■
stc chan struct{} ■ ■ ■ ■ ■ ■ ■ ■
cw *s2.Writer ■ ■ ■ ■ ■ ■ ■ ■
}
Signed-off-by: Neil Twigg <neil@nats.io>
19455da to
ab6896a
Compare
This was referenced Nov 5, 2025
neilalexander
added a commit
that referenced
this pull request
Nov 5, 2025
neilalexander
added a commit
that referenced
this pull request
Nov 5, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new
write_timeoutconfiguration option which controls the slow consumer behaviour more precisely with what happens when thewrite_deadlineis reached. This option can be set for clients, routes, gateways or leafnodes independently. Three values are supported:default: functionality as it stands today,retryfor route/gateway/leafnode,closefor clientretry: when hitting thewrite_deadline, keep retrying writes until either we succeed or the ping interval hitsclose: when hitting thewrite_deadline, close the connection immediatelySigned-off-by: Neil Twigg neil@nats.io