Skip to content

Reject savepoints and nested begins when the connection is lost (#1281) - #1282

Merged
porsager merged 1 commit into
porsager:masterfrom
RagedPanda:fix/savepoint-connection-lost
Nov 1, 2026
Merged

porsager merged 1 commit into
porsager:masterfrom
RagedPanda:fix/savepoint-connection-lost

Conversation

@RagedPanda

Copy link
Copy Markdown
Contributor

Fixes #1281.

When the connection drops while a tx.savepoint() or nested tx.begin() callback is still running, the root sql.begin() rejects with CONNECTION_CLOSED (through lease.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 after await tx.savepoint(...) runs its success path although PostgreSQL has aborted the transaction.

The fix: after the callback settles, a scope throws lease.connection.closed if 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 same CONNECTION_CLOSED error as the root.

Test: A savepoint or nested begin rejects when the connection is lost while its callback runs (#1281) in tests/transactions.js follows 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. On 4.0.0 both children resolve (CONNECTION_CLOSED fulfilled); with this change both reject with CONNECTION_CLOSED.

node tests/transactions.js against PostgreSQL 17 (with max_prepared_transactions set 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.

@porsager

porsager commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Good catch! Thank you

@porsager
porsager merged commit 2e52628 into porsager:master Nov 1, 2026
70 of 72 checks passed
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v4: savepoint and nested begin promises fulfill after connection loss rejects the root transaction

2 participants