Skip to content

[13.x] Release the unique lock when pushing a queued listener fails - #62045

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
mrjavadseydi:fix-unique-listener-lock-on-failed-push
Oct 15, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
mrjavadseydi:fix-unique-listener-lock-on-failed-push

Conversation

@mrjavadseydi

Copy link
Copy Markdown
Contributor

When a unique queued listener is dispatched, Dispatcher::queueHandler() acquires the unique lock before pushing it to the queue. If the push throws (queue database or redis is down) the lock is never released, so every dispatch after that is silently skiped untill the lock expires, even after the queue is back.

class SendInvoice implements ShouldQueue, ShouldBeUnique
{
    public function handle(OrderPlaced $event)
    {
        // ...
    }
}

event(new OrderPlaced($order)); // throws, queue is down

// queue is back up

event(new OrderPlaced($order)); // silently skipped until the lock expires

Jobs already got this fix in #62010, this does the same for listeners. everything after the lock is acquired is wrapped so the lock gets released if anything throws, then the exeption is rethrown:

try {
    // resolve connection, queue, delay...

    is_null($delay)
        ? $connection->pushOn(enum_value($queue), $job)
        : $connection->laterOn(enum_value($queue), $delay, $job);
} catch (Throwable $e) {
    if ($job->shouldBeUnique) {
        (new UniqueLock($this->container->make(Cache::class)))->release($job);
    }

    throw $e;
}

Added a test that use a failing queue connection, same as the one in #62010.

@github-actions

Copy link
Copy Markdown

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.

@mrjavadseydi
mrjavadseydi marked this pull request as ready for review October 15, 2026 20:22
@taylorotwell
taylorotwell merged commit fbc2b3e into laravel:13.x Oct 15, 2026
64 checks passed
@mrjavadseydi
mrjavadseydi deleted the fix-unique-listener-lock-on-failed-push branch October 16, 2026 10:09
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