fix(state): don't wait for a ReadyForQuery the server will never send - #1356
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
jkaczman
marked this pull request as ready for review
August 13, 2026 17:38
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.
A client using Postgrex's
mode: :savepointhangs on any query that errors. The error is returned to the client, but the client never gets theReadyForQuerythat lets it show the error to the caller. It hangs until reaching timeout.Postgrex sends
Bind(extended),Execute(extended), and a simpleQuery("RELEASE SAVEPOINT ...")as one batch. It doesn't include a Sync in that batch, it does afterwards though, as part of error recovery.When the
Executeerrors, the server gets rid of all messages until a Sync comes. This includes the RELEASE query previously mentioned. However, due to the mixed nature of the batch (extended, extended, simple), PgDog expects a ReadyForQuery back...PgDog queued the same expectation (
Z) for both Sync-owed and Query-owed RFQ, so our error branch instate.rs's actionmethod couldn't tell them apart. Thus, it re-queued the trailing RFQ unconditionally, and that being the only entry that survived kepthas_more_messages()true inserver.rs, so PgDog stayed infinitely stuck on the server socket, and never read the Sync the client had already sent.Essentially a Deadlock: client waits on PgDog, PgDog waits on server, server waits on a Sync (which is sitting unread in PgDog's client socket).
What I changed:
ReadyForQueryandReadyForQuerySync. After an extended-protocol error, the server only ever answers the Sync, so we need a way to distinguish them.'C' | 's' | 'I'lump intoCommandCompleteandExecutionCompleted.CommandCompletecan come from a simple Query or from an extended Execute. An Execute one means error skips to a sync, so we need to differentiate there too.Tests: added two state.rs regression tests, three new Elixir integration tests, did some small updates to some state.rs tests to update to the new variants.
Fixes #1314