[12.x] Fix closure in chain not dispatched after batch completes#59492
Closed
JoshSalway wants to merge 1 commit into
Closed
[12.x] Fix closure in chain not dispatched after batch completes#59492JoshSalway wants to merge 1 commit into
JoshSalway wants to merge 1 commit into
Conversation
When Bus::chain contains a closure after a Bus::batch, the closure fails with 'Call to undefined method Closure::getClosure()'. This happens because attachRemainderOfChainToEndOfBatch() captures the next chain item (a CallQueuedClosure containing a SerializableClosure) directly in the batch's finally callback. When the batch serializes this callback, the nested SerializableClosure gets unwrapped to a raw Closure during the round-trip. Fix by re-serializing the next chain item to a string before capturing it in the finally closure.
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
This comment was marked as spam.
This comment was marked as spam.
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.
Summary
Backport of #59491 to 12.x. Fixes a bug where a closure in
Bus::chainis not dispatched when it follows aBus::batch, throwingCall to undefined method Closure::getClosure().Relates to laravel/serializable-closure#106
Problem
ChainedBatch::attachRemainderOfChainToEndOfBatch()captures the next chain item directly in the batch'sfinallycallback. When the batch serializes this callback, the nestedSerializableClosureinside$next->closuregets unwrapped to a rawClosureduring the round-trip.Solution
Re-serialize
$nextto a string before capturing it in thefinallyclosure. The string is deserialized at dispatch time.Test plan
testClosureAfterBatchInChainIsDispatchedinJobChainingTest.php