Skip to content

[13.x] Release unique job locks in Queue::fakeFor() - #61824

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
xurshudyan:queue-fake-for-unique-locks
Oct 2, 2026
Merged

taylorotwell merged 2 commits into
laravel:13.xfrom
xurshudyan:queue-fake-for-unique-locks

Conversation

@xurshudyan

Copy link
Copy Markdown
Contributor

Queue::fakeFor() and Queue::fakeExceptFor() swap the original queue manager back when the callback finishes, but they never release the unique locks taken by jobs dispatched inside the callback. The fake never runs those jobs, so the locks stay in the cache until uniqueFor expires, or forever when it isn't set.

So if the same unique job is dispatched again after the callback, it gets skipped:

Queue::fakeFor(function () {
    ImportUsers::dispatch();
});

ImportUsers::dispatch(); // skipped, the lock is still held

#58718 fixed this for Queue::fake() by calling releaseUniqueJobLocks() when faking again. This PR calls it in the finally block of fakeFor() and fakeExceptFor() too. releaseUniqueJobLocks() now returns early when no unique jobs were pushed, so it doesn't resolve the cache when there is nothing to release.

@taylorotwell
taylorotwell merged commit e9d1518 into laravel:13.x Oct 2, 2026
62 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