Repository navigation
Reject savepoints and nested begins when the connection is lost (#1281) - #1282
Merged
porsager merged 1 commit intoNov 1, 2026
Merged
Conversation
Owner
|
Good catch! Thank you |
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
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 #1281.
When the connection drops while a
tx.savepoint()or nestedtx.begin()callback is still running, the rootsql.begin()rejects withCONNECTION_CLOSED(throughlease.closed), but the child scope has no such check. Once its callback returns, a named scope skips the commit and resolves with the callback's value, so code afterawait tx.savepoint(...)runs its success path although PostgreSQL has aborted the transaction.The fix: after the callback settles, a scope throws
lease.connection.closedif the connection is gone. That goes through the existing catch, which already skips the rollback on a closed connection, so the child rejects with the sameCONNECTION_CLOSEDerror as the root.Test:
A savepoint or nested begin rejects when the connection is lost while its callback runs (#1281)intests/transactions.jsfollows the issue's repro. It terminates the backend from a second client while the child callback waits on a gate, waits for the root to reject, then releases the callback. On4.0.0both children resolve (CONNECTION_CLOSED fulfilled); with this change both reject withCONNECTION_CLOSED.node tests/transactions.jsagainst PostgreSQL 17 (withmax_prepared_transactionsset as in CI): 63 of 64 pass. The remaining one is the #951 proxy test, which connects to a hardcoded port 5432 and fails the same way without this change in my setup. ESLint reports nothing new.I used an AI coding assistant (Claude) to help with this change; I reviewed and tested it myself.