Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

theone's avatar

Serialization failure: 1213 Deadlock found when trying to get lock

Getting Deadlock in jobs table , I'm using supervisor , If i use Redis this will be solved ,But if there is any solutions for mysql Please let me know.

SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and `available_at` <= 1642088282) or (`reserved_at` <= 1642088192)) order by `id` asc limit 1 for update) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 40001): SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction (SQL: select * from `jobs` where `queue` = default and ((`reserved_at` is null and `available_at` <= 1642088282) or (`reserved_at` <= 1642088192)) order by `id` asc limit 1 for update) at /var/www/utllv/data/www/utllv.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669)

0 likes
7 replies
Tray2's avatar

Without seeing any code it's hard to help you but deadlocks occur when more than one process is trying to do something with the same record, or when the database calls are extremely frequent and you have more than one index on the table. The indexes lock each other if they are updated very frequently.

So tell us what you are trying to do and show some code and we might be able to give you some advice on how to solve the issue,

theone's avatar

@Tray2 Thanks for the reply , Actually it's an API call and it's inserting data fetched from API , I think the first process takes long so the next one Also picking the same job ,please let me know which part of the code you need to see i'll post

theone's avatar

@Tray2 Is there is anything , i can start the job only one time , i set timeout = 0 ; too but it didn't work

Sinnbeck's avatar

@theone why is it running more than once? Retries? You can set it to a lower number. You can also add without overlap

theone's avatar

@Sinnbeck i removed retry too But it keeps throwing the error . Is there is Any way to debug So i can get more details and try things

Please or to participate in this conversation.