Drain connections when more messages are expected #667
+91
−2
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).