Don't wait for ReadyForQuery after FATAL errors#765
Open
Conversation
v0idpwn
commented
Mar 18, 2026
Comment on lines
+3071
to
3077
| defp error_ready(s, _status, %Postgrex.Error{postgres: %{severity: severity}} = err, buffer) | ||
| when severity in ["FATAL", "PANIC"] do | ||
| %{connection_id: connection_id} = s | ||
| {:disconnect, %{err | connection_id: connection_id}, %{s | buffer: buffer}} | ||
| end | ||
|
|
||
| defp error_ready(s, status, %Postgrex.Error{} = err, buffer) do |
Member
Author
There was a problem hiding this comment.
I don't love that this is called error_ready but couldn't come up with a better name for the new implementation.
Member
Author
There was a problem hiding this comment.
I think maybe instead of returning {:disconnect, ...} immediately, it should wait for ReadyForQuery or for the socket closed to be closed (which is what libpq does, if I'm not mistaken), then return the error.
When PostgreSQL sends a FATAL or PANIC ErrorResponse, it closes the connection immediately without sending ReadyForQuery. Postgrex unconditionally waited for ReadyForQuery, which would hit tcp_closed and return a generic disconnect error, discarding the original FATAL error.
be2740a to
b3eb658
Compare
v0idpwn
commented
Mar 18, 2026
Member
Author
v0idpwn
left a comment
There was a problem hiding this comment.
I think SimpleConnection may need some error handling tweak to handle this too. I'll look into that tomorrow 🙏🏻
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.
When PostgreSQL sends a FATAL or PANIC ErrorResponse, it closes the connection immediately without sending ReadyForQuery.
Postgrex unconditionally waited for ReadyForQuery, which would hit tcp_closed and return a generic disconnect error, discarding the original error message.
I've included in the PR a test that would fail with the previous implementation. The query would return a