Drain connections when more messages are expected#667
Closed
jbielick wants to merge 1 commit into
Closed
Conversation
The needs_drain() condition prior to this commit checks the connection state is some kind of idle or otherwise "in sync". However, even when the connection state is Idle, there can be expected messages in the protocol queue. If a client disconnects abruptly at just the right time, needs_drain() would not return true, but the protocol queue is not empty and expected messages from the server are not drained. In this scenario, the connection is checked back in in a tainted state and subsequent usage can produce unexpected results (ProtocolOutOfSync or off-by-1 results mixups). This updates needs_drain() to also account for prepared_statements.has_more_messages() in addition to the "in sync" check, thus triggering a drain when there are more messages expected from the server (and tracked in the protocol queue).
9567327 to
2369f72
Compare
jbielick
commented
Dec 10, 2025
Comment on lines
+672
to
+673
| ProtocolMessage::from(Query::new("SELECT 1")), | ||
| ProtocolMessage::from(Query::new("SELECT 1")), |
Contributor
Author
There was a problem hiding this comment.
Holding off on this PR because stuffing the ClientRequest like this doesn't seem to be a realistic reproduction. Addressing some of the out-of-sync side effects in #668 instead.
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.
Purpose
#565
The
needs_drain()condition prior to this commit checks the connection state is some kind of idle or otherwise "in sync". However, even when the connection state is Idle, there can be expected messages in the protocol queue. If a client disconnects abruptly at just the right time, needs_drain() would not return true, but the protocol queue is not empty and expected messages from the server are not drained.In this scenario, the connection is checked back in in a tainted state and subsequent usage can produce unexpected results (ProtocolOutOfSync or off-by-1 results mixups).
Fix
This updates
needs_drain()to also account forprepared_statements.has_more_messages()in addition to the "in sync" check, thus triggering a drain when there are more messages expected from the server (and tracked in the protocol queue).