Repository navigation
fix: reject transactions with the FATAL error the server sent before closing - #1284
Merged
Merged
Conversation
porsager
added a commit
that referenced
this pull request
Nov 1, 2026
With #1284 a transaction whose connection the server ends rejects with the server's FATAL error, while #1282 made a savepoint or nested begin left running reject with the connection's CONNECTION_CLOSED. Both now reject with the error the transaction's connection closed with. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01CDChydjdmWh3wYY7rqYz5D
Owner
|
Thanks a lot! |
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.
Fixes #1283
When the server ends a session with a FATAL
ErrorResponse(25P04transaction_timeout,25P03idle_in_transaction_session_timeout,57P01pg_terminate_backend),sql.beginrejected with a genericCONNECTION_CLOSED. That made it impossible to tell a configured timeout or an operator termination from a network drop.Two things caused this:
transaction()races the callback againstlease.closed.lease.closedrejects synchronously in the pool'sonclose, so it always wins against the in-flight query, which had already been rejected with the FATAL error.closed.causeonly picked upconnection.fatal, which is set only when the FATAL arrives with no query in flight. A FATAL that arrived for an in-flight query was not attached anywhere else.Changes:
src/connection.js: when the in-flight query received a FATAL, it now also becomes thecauseof theCONNECTION_CLOSEDerror. A FATAL received while idle was already the cause.src/pool.js: a lease (sql.begin) whose connection closed because of a server FATAL now rejects with that FATAL error instead ofCONNECTION_CLOSED.Queries made on the dead connection afterwards still reject with
CONNECTION_CLOSED, now with the FATAL ascausein every case. Plain queries that were in flight already rejected with the FATAL error, so they are unchanged.Behaviour change:
sql.beginnow rejects with the server's SQLSTATE (25P03,57P01, ...) where it used to reject withCONNECTION_CLOSED. Two existing tests that assertedCONNECTION_CLOSEDfor exactly this case are updated:idle_in_transaction_session_timeout rejects the transactionandDisconnect rejects queued transaction queries....Tests added in
tests/transactions.js:25P04) during an in-flight query (PostgreSQL 17+, skipped on older servers)57P01) during an in-flight query in a transactionsql.beginrejects with57P01, and the next query rejects withCONNECTION_CLOSEDthat hascause.code === '57P01'All three new tests fail on master and pass with this change.
This PR was prepared with AI assistance (Claude). I reviewed and tested the change myself.