[13.x] [bug] Fix closure in chain not dispatched after batch completes#59491
Draft
JoshSalway wants to merge 3 commits intolaravel:13.xfrom
Draft
[13.x] [bug] Fix closure in chain not dispatched after batch completes#59491JoshSalway wants to merge 3 commits intolaravel:13.xfrom
JoshSalway wants to merge 3 commits intolaravel:13.xfrom
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. The string is deserialized at dispatch time, avoiding the serializable-closure library needing to traverse into the CallQueuedClosure's properties.
|
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. |
Verifies that a closure following a Bus::batch inside Bus::chain is correctly dispatched after the batch completes. This was broken because attachRemainderOfChainToEndOfBatch captured a live CallQueuedClosure in the finally callback, causing the nested SerializableClosure to get unwrapped during serialization.
1 task
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
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
Root cause
The root cause is in
serializable-closure'sNative::__unserialize(). When deserializing a closure that captures an object with aSerializableClosureproperty, the objects restoration loop unconditionally callsgetClosure()on all stored objects, includingSerializableClosureinstances that should be preserved as-is. This unwraps them to rawClosureobjects, breaking any code that later callsgetClosure()on the property.PR laravel/serializable-closure#135 fixes this at the library level with an
instanceofcheck before callinggetClosure().This PR (framework-level alternative)
If the serializable-closure fix is not accepted, this PR provides a framework-level workaround specific to
ChainedBatch. It re-serializes$nextto a string before capturing it in thefinallyclosure, so the serializable-closure library never traverses into theCallQueuedClosure's properties:Reproduction
Test plan
testClosureAfterBatchInChainIsDispatchedinJobChainingTest.php