Skip to content

[12.x] Resolve infinite loop when using deferred queue#58373

Merged
taylorotwell merged 2 commits into
laravel:12.xfrom
cosmastech:patch-35
Jan 15, 2026
Merged

[12.x] Resolve infinite loop when using deferred queue#58373
taylorotwell merged 2 commits into
laravel:12.xfrom
cosmastech:patch-35

Conversation

@cosmastech

@cosmastech cosmastech commented Jan 14, 2026

Copy link
Copy Markdown
Contributor

To close #58351

Tested this locally. As described in the issue, this spawns an infinite loop. After this change, the job is executed and no infinite loop.


$this->app['events']->listen(function (JobAttempted $event) {
app(DeferredCallbackCollection::class)->invokeWhen(fn ($callback) => $event->connectionName !== 'sync' && ($event->successful() || $callback->always));
app(DeferredCallbackCollection::class)->invokeWhen(static fn ($callback) => ! in_array($event->connectionName, ['sync', 'deferred']) && ($event->successful() || $callback->always));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the comparison be strict i.e. passing true?
I don't know the code practices in here, but I believe for two values, two checks is faster than in_array. Though the difference would be minimal but the two conditions will support short circuiting.

@taylorotwell taylorotwell merged commit 8d0c031 into laravel:12.x Jan 15, 2026
70 checks passed
@cosmastech cosmastech deleted the patch-35 branch January 24, 2026 13:05
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.

Specifying connection deferred on a Job causes an infinite loop starting from v12.45.0 and till current

3 participants