fix: release START_TXN nesting level on SQLException paths in GenericDaoBase sibling methods - #13926
Open
waterWang wants to merge 1 commit into
Open
fix: release START_TXN nesting level on SQLException paths in GenericDaoBase sibling methods#13926waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
…DaoBase sibling methods update(ID,...), update(ub,sc,rows), expunge(ID), insertElementCollection, expunge(), unremove(ID) and remove(ID) call txn.start() which pushes a START_TXN nesting level onto the caller's transaction stack, but their SQLException catch blocks throw without reaching txn.commit() and without a finally rollback. The leaked nesting level makes the caller's commit() silently no-op, discarding all work done in the transaction. Add a committed flag and roll back in finally when commit was not reached, mirroring the fix for apache#13905 in persist(). Signed-off-by: waterWang <waterwang@proton.me>
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.
Bug
GenericDaoBasecontains seven sibling methods that leak a transaction nesting level on SQLException paths, same root cause as #13905 (persist()— fixed in #13925):update(ID, UpdateBuilder, T)update(UpdateBuilder, SearchCriteria, Integer)expunge(ID)insertElementCollection(...)expunge()unremove(ID)remove(ID)Root cause
TransactionLegacy.start()pushes aSTART_TXNstack element onto the caller's transaction stack and sets_txn = true. Each of these methods callstxn.start(), but when theSQLExceptioncatch block throws, control never reachestxn.commit(). Because there is nofinallyrollback, the pushedSTART_TXNstays on the stack forever.The caller's own
commit()then finds the transaction stack still balanced with aSTART_TXNentry (hasTxnInStack() == true) and silently returnsfalse, logging onlyNot committing because transaction started elsewhere. Every change made inside the caller's transaction is silently discarded while the caller believes it committed.For Example,
remove(ID)on an entity with aremovedcolumn:Fix
Mirror the
persist()fix from #13925: add aboolean committedflag, set it totrueright aftertxn.commit(), and roll back in afinallyblock when commit was never reached:rollback()pops theSTART_TXNlevel and, when it was the outermost one, performs a real DB rollback — so the caller receives a genuine failure instead of a silent no-op.Signed-off-by: waterWang waterwang@proton.me