Skip to content

[12.x] Don't fail database queue jobs on deadlock#59199

Open
jackbayliss wants to merge 4 commits intolaravel:12.xfrom
jackbayliss:12.x-ensure-concurrency-issue-doesnt-fail
Open

[12.x] Don't fail database queue jobs on deadlock#59199
jackbayliss wants to merge 4 commits intolaravel:12.xfrom
jackbayliss:12.x-ensure-concurrency-issue-doesnt-fail

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Mar 13, 2026

The index added in #59111 seems to have caused a lot of deadlocks, at least for me, which means I now have a lot of failed jobs, and logs due to concurrency errors, because I have a lot of workers listening on the same queues, rather than just one.

Rather than reverting that PR, thought I'd try this as I guess the index is useful still. But up to you 👍🏻

Currently I have a bunch of jobs in the failed_jobs table, where concurrency issues happen during marshalJob / markJobAsReserved

This PR returns null on concurrency errors so the worker moves on quietly, leaving the job available for the next poll and stops spamming logs.

Added a test for regression too.

Images / Trace here image
1213 Deadlock found when trying to get lock; try restarting transaction (Connection: mysql, Host: xxxx), Port: 3306, Database: zzzz, SQL: update `jobs` set `reserved_at` = 1773439353, `attempts` = 1 where `id` = 112812452)

/srv/app/my-secret-app/x/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:422                                                          
/srv/app/my-secret-app/x/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:408                                                                                    
/srv/app/my-secret-app/x/vendor/laravel/framework/src/Illuminate/Queue/DatabaseQueue.php:294

@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 March 13, 2026 23:23
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.

1 participant