Fix stale _transactionException after ROLLBACK TO SAVEPOINT - #455
Closed
kartikey321 wants to merge 1 commit into
Closed
Fix stale _transactionException after ROLLBACK TO SAVEPOINT#455kartikey321 wants to merge 1 commit into
kartikey321 wants to merge 1 commit into
Conversation
When any PgException occurred inside runTx, _transactionException was set and never cleared — even after a successful ROLLBACK TO SAVEPOINT restored PostgreSQL to a healthy state. mayCommit therefore returned false and the driver sent ROLLBACK instead of COMMIT, silently discarding all subsequent work that completed successfully at the PostgreSQL level. Fix: clear _transactionException in _handleMessage whenever PostgreSQL sends ReadyForQuery with state='T' (InTransaction), which is the authoritative signal that the connection is in a clean, committable state.
Contributor
Author
|
This pr changes are merged in another pr #457 Closing this one |
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 #454
Problem
When any
PgExceptionoccurred insiderunTx, the internal_transactionExceptionfield was set and nevercleared — even after a successful
ROLLBACK TO SAVEPOINTrestored PostgreSQL to a healthy state.mayCommittherefore returned
falseand the driver sentROLLBACKinstead ofCOMMIT, silently discarding all subsequentwork that completed successfully at the PostgreSQL level.
Root cause
_handleMessagesets_transactionExceptionon everyErrorResponseMessage(line 531) but has no path to clearit. After
ROLLBACK TO SAVEPOINT, PostgreSQL sendsReadyForQuery(state='T')— the authoritative signal that theconnection is in a clean, committable state — which the driver was ignoring for this purpose.
Fix
Clear
_transactionExceptionin_handleMessagewhen aReadyForQuerywithstate='T'is received. This matchesthe approach taken by asyncpg and pgx,
both of which treat
ReadyForQuery('T')as the signal that the connection is healthy.Testing
Added a regression test in
test/transaction_test.dartthat:42P01error insiderunTxROLLBACK TO SAVEPOINT/RELEASE SAVEPOINTThe test fails on the original code and passes with this fix.