Skip to content

[12.x] Ignore deadlock on DatabaseLock release#58507

Merged
taylorotwell merged 3 commits intolaravel:12.xfrom
jackbayliss:12.x-ignore-concurrency-errors-on-release
Jan 27, 2026
Merged

[12.x] Ignore deadlock on DatabaseLock release#58507
taylorotwell merged 3 commits intolaravel:12.xfrom
jackbayliss:12.x-ignore-concurrency-errors-on-release

Conversation

@jackbayliss
Copy link
Contributor

@jackbayliss jackbayliss commented Jan 26, 2026

When using shared database locks (ie WithoutOverlapping with shared()), when running multiple workers, multiple jobs can have the same lock owner and race when releasing simultaneously, causing deadlocks on the cache_locks table.

This is happening for me in production environments:

Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (Connection: mysql, Host: my-database, Port: 3306, Database: my database-, SQL: delete from `cache_locks` where `....

This PR uses the existing DetectsConcurrencyErrors trait to catch and ignore deadlock errors - ie exactly the same as we have in pruneExpiredLocks

Added test coverage. Feedback welcome 🫡

@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 January 26, 2026 12:23
@taylorotwell taylorotwell merged commit b877493 into laravel:12.x Jan 27, 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