fix: release START_TXN nesting level on persist() SQLException path (#13905) - #13925
Open
waterWang wants to merge 1 commit into
Open
fix: release START_TXN nesting level on persist() SQLException path (#13905)#13925waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…pache#13905) GenericDaoBase.persist() calls txn.start() which pushes a START_TXN nesting level onto the caller's transaction stack. The SQLException catch block throws without reaching txn.commit(), so the nesting level is leaked. The caller's subsequent commit() finds the transaction unbalanced and silently no-ops — all caller work in that batch is lost with no error. Fix: track commit success and roll back the START_TXN level in a finally block when commit() was not reached, ensuring the caller's transaction is restored to a balanced state instead of silently abandoning its work. Closes apache#13905 Signed-off-by: waterWang <waterwang@proton.me>
waterWang
force-pushed
the
fix-persist-txn-leak-13905
branch
from
August 20, 2026 05:35
36514dd to
a829bf1
Compare
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.
Description
GenericDaoBase.persist()callstxn.start()which pushes aSTART_TXNnesting level onto the caller's transaction stack. When the insert throwsSQLException, the catch block rethrows without reachingtxn.commit(), so the pushed nesting level is leaked. The caller's latercommit()then finds the transaction unbalanced and silently no-ops (logging onlytxn: Commit called when it is not a transaction), discarding everything the caller believed it committed.Callers that deliberately catch
EntityExistsExceptionto log-and-continue cannot actually continue, because the enclosing transaction is already unrecoverable — this converts a single constraint violation into permanent failure (see #13399).Fix
Track commit success via a
committedflag; in afinallyblock, roll back the transaction when the commit was not reached, restoring the caller's transaction to a balanced state.Types of changes
How has this been tested?
Code-review level only — the change adds a rollback guard to the existing try/catch structure. Existing tests cover DAO persist paths.
Closes #13905