Skip to content

[12.x] Ensure defer callbacks aren't discarded when using the sync queue#58745

Merged
taylorotwell merged 4 commits intolaravel:12.xfrom
jackbayliss:12.x-have-a-go-defer-bizness
Feb 10, 2026
Merged

[12.x] Ensure defer callbacks aren't discarded when using the sync queue#58745
taylorotwell merged 4 commits intolaravel:12.xfrom
jackbayliss:12.x-have-a-go-defer-bizness

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Feb 10, 2026

Reported via #58731

Currently, if you use the sync driver to dispatch a job as well as using defer during the request, the defer callbacks will be lost - which I don't think is expected behaviour.

A scenario this would be used is something like:

Route::post('/orders', function () {
    $order = Order::create($data);

    // Send confirmation email
    dispatch(new SendOrderConfirmation($order));

    // Defer something for after the response... - this is currently not executed
    defer(fn () => Metrics::reportOrder($order));

    return response()->json($order);
});

I've added a new test to cover it as couldnt find anything callback wise for tests. You can drop the FoundationServiceProvider change and the test will fail.

TLDR is basically this happens when using the sync queue with defer

You may see a better way so feel free to adjust etc as you see fit 🫡 I didn't want to go sledgehammer on it

Targeted 12.x as seems like a bug

@github-actions
Copy link

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.

@jackbayliss jackbayliss marked this pull request as ready for review February 10, 2026 19:09
@taylorotwell taylorotwell merged commit 8bf83cf into laravel:12.x Feb 10, 2026
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants