Repository navigation
fix(#6457): recognize COMMIT/ROLLBACK/END over the Postgres simple-query protocol - #6542
Conversation
…ery protocol
Over the simple-query ('Q') wire protocol, once a statement failed inside an
explicit BEGIN block the session became permanently wedged:
- queryCommand() recognized only BEGIN, never COMMIT/ROLLBACK/END, so there
was no statement that could ever end an aborted transaction block.
- While aborted, every subsequent statement was silently swallowed (no
ErrorResponse, no CommandComplete), leaving the client with no signal its
statement never ran.
- writeReadyForQueryMessage() never reported the aborted status 'E', so even
a client checking the wire-level transaction status had no way to detect
the failure.
This also affected the non-aborted path: a plain COMMIT/ROLLBACK fell
through to the SQL engine as an ordinary statement and never cleared
explicitTransactionStarted, so ReadyForQuery kept reporting 'T' after commit.
Fix, matching real Postgres semantics:
- queryCommand()'s normal dispatch now recognizes COMMIT/COMMIT TRANSACTION/
END/END TRANSACTION and ROLLBACK/ROLLBACK TRANSACTION, committing or rolling
back the underlying transaction and clearing explicitTransactionStarted.
- While aborted, COMMIT/ROLLBACK/END now roll back and clear the aborted
state (a COMMIT of a failed transaction acts as a ROLLBACK, per Postgres),
while every other statement gets an ErrorResponse with SQLSTATE 25P02
("current transaction is aborted") instead of being swallowed.
- writeReadyForQueryMessage() reports 'E' whenever errorInTransaction is set.
- getTag() gains COMMIT/ROLLBACK tags for CommandComplete.
Verified with a new IT that speaks the wire protocol directly over a raw
socket to assert on the ReadyForQuery status byte and ErrorResponse content.
|
Tick the box to add this pull request to the merge queue (same as
|
ReviewSolid, well-scoped bug fix. The three defects described in the PR body all check out against the code, and the fix for each is exactly where you'd expect it:
The new helpers ( Test coverageStrong. Driving the simple-query protocol over a raw socket instead of through the JDBC driver is the right call here since it lets the test assert on the exact Minor / non-blocking suggestions
Performance / securityNo concerns. The added checks are cheap string comparisons on an already-uppercased string, no new allocations of note, and there's no new user-controlled input reaching anything sensitive (SQL execution, file I/O, etc.) beyond what already existed. Nice fix, this closes a real "wedged session" bug with good regression coverage. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 24 |
🟢 Coverage 83.87% diff coverage · -6.50% coverage variation
Metric Results Coverage variation ✅ -6.50% coverage variation Diff coverage ✅ 83.87% diff coverage Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (03cb038) 163714 130755 79.87% Head commit (d3ee423) 196545 (+32831) 144206 (+13451) 73.37% (-6.50%) Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#6542) 31 26 83.87% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Per review feedback on PR #6542: add a one-line comment at the writeCommandComplete("ROLLBACK", 0) call site itself, not just on the isTransactionEndStatement() helper, since a reader skimming only queryCommand() could otherwise wonder why a COMMIT/END request writes a "ROLLBACK" CommandComplete tag.
|
Review Solid, well-scoped fix for #6457. The three defects described in the PR body line up with what's in the diff, and the new IT talks to the wire protocol over a raw socket so it can actually assert on the Correctness
Minor / non-blocking observations
Test coverage Performance / security |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6542 +/- ##
==========================================
+ Coverage 71.16% 71.20% +0.03%
==========================================
Files 1865 1866 +1
Lines 163714 164158 +444
Branches 34575 34688 +113
==========================================
+ Hits 116508 116882 +374
- Misses 33000 33038 +38
- Partials 14206 14238 +32 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Closes #6457
Problem
Over the Postgres simple-query ('Q') wire protocol, once a statement erred inside an explicit
BEGINblock the session became permanently wedged, with three separate defects inPostgresNetworkExecutor:writeReadyForQueryMessage()never reported the aborted status'E'- only'T'(in a transaction) or'I'(idle) - so a client had no wire-level signal the transaction had failed.queryCommand()recognized onlyBEGIN, neverCOMMIT/ROLLBACK/END. There was no statement over the simple-query path that could ever end an aborted block, and even without a prior error a plainCOMMIT/ROLLBACKfell through to the SQL engine as an ordinary (failing) statement, leavingexplicitTransactionStartedstucktrueforever.queryCommand()silently returned for every statement - noErrorResponse, noCommandComplete- so the client couldn't tell its statement never ran, and writes made before the error were left in limbo.Fix
postgresw/src/main/java/com/arcadedb/postgres/PostgresNetworkExecutor.java:writeReadyForQueryMessage()now reports'E'whenevererrorInTransactionis set (checked before theexplicitTransactionStarted/'T'branch).queryCommand()gainsCOMMIT/COMMIT TRANSACTION/END/END TRANSACTIONandROLLBACK/ROLLBACK TRANSACTIONhandling, committing or rolling back the underlying transaction and clearingexplicitTransactionStarted(previously never cleared on a plainCOMMIT/ROLLBACK).errorInTransactionbranch now recognizes those same end-of-transaction keywords: it rolls back and clears the aborted state, matching real Postgres semantics where aCOMMITof a failed transaction acts as aROLLBACK(with a warning) rather than trying to persist writes that already failed. Every other statement while aborted now gets anErrorResponsewith SQLSTATE25P02("current transaction is aborted, commands ignored until end of transaction block") instead of being silently swallowed.getTag()gainsCOMMIT/ROLLBACKtags forCommandComplete.Test plan
New IT
postgresw/src/test/java/com/arcadedb/postgres/Issue6457AbortedTransactionSimpleQueryIT.javaspeaks the simple-query wire protocol directly over a raw socket (not through the JDBC driver) so the exactReadyForQuerystatus byte andErrorResponsecontent can be asserted on:'E', refuses further statements with SQLSTATE25P02untilROLLBACK, and the session is fully usable again afterward.COMMITof an aborted transaction acts asROLLBACKand discards the writes made before the error.COMMITwith no prior error is recognized over the simple-query protocol, ends the transaction (status back to'I'), and persists the writes.Verification run (isolated
-Dmaven.repo.local, port 2480 freed from the local brewarcadedbservice beforehand and restarted after):mvn -pl postgresw verify -Dit.test=Issue6457AbortedTransactionSimpleQueryIT -DskipITs=false: new IT green, 3/3.mvn -pl postgresw verify -DskipITs=false(full module, unit + IT): all green, 408 unit tests + 169 integration tests, 0 failures/errors - no regressions from the COMMIT/ROLLBACK/END dispatch changes.