[13.x] Execute rollback callbacks for committed savepoints (follow-up to #55420)#60482
Open
sulimanbenhalim wants to merge 1 commit into
Open
Conversation
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.
Hi team
Hit this one in production today. Took me hours to figure out.
Setup: controller wraps its work in
DB::transaction. Inside it calls a service that does its ownDB::transaction(so a savepoint). Service dispatches aShouldBeUniquejob withafter_commit => true. After all the work the controller calls the payment gateway. Gateway throws. Outer rolls back.Expected: job not queued. Unique lock released. Move on.
What actually happens: job not queued (correct) but the unique lock is NEVER released. Every future dispatch of that job silently does nothing forever.
Took me a while to find why. PR #55420 added the rollback callback mechanism a few months ago which is exactly the right idea. It fires
executeCallbacksForRollback()for the OPEN transaction chain. But when an inner savepoint commits its record moves frompendingTransactionstocommittedTransactions. Then when the outer rolls backremoveAllTransactionsForConnectionjust->reject()s those committed records without firing their callbacks.Same gap in
removeCommittedTransactionsThatAreChildrenOf(the partial rollback path).Fix
Fire the callbacks before dropping the committed records. The callbacks already exist on the record. Nobody just calls them in this path.
3 lines in
removeAllTransactionsForConnection. 1 line inremoveCommittedTransactionsThatAreChildrenOf.Tests
Added 2 tests next to
testRollbackTransactionsExecutesCallbacks:All 17
DatabaseTransactionsManagerTestpass. All 52EloquentTransactionWithAfterCommit*integration tests across the 5 variants pass.Backward compat
Zero behavior change for code that does not register rollback callbacks on inner savepoints. Code that does (i.e.
ShouldBeUniquewithafter_commitinside nested transactions) finally sees the rollback callbacks it registered actually run.Same incomplete-fix-completion shape as the recent #60149 cleanup if that helps frame review.
Thanks