hi guys. im running a laravel 8 application and i keep seeing this in my error logs:
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 <= 1703015588) or (reserved_at <= 1703015578)) 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 <= 1703015588) or (reserved_at <= 1703015578)) order by id asc limit 1 for update)
ofcourse the numbers can vary based on the time, but this is how it locks.
Does anyone know why it happens?
I have supervisor running the 5 workers on
artisan queue:work database --sleep=3 --tries=3
and 5 more running like this:
artisan queue:work redis --sleep=3 --tries=1 --timeout=200
can it be the timeout that is causing this? or is it because i'm retrying a process that is already running?
It seems you still use MySQL for your jobs table which is not suitable in a production environment, I suggest configuring your .env file:
QUEUE_CONNECTION=redis
QUEUE_FAILED_DRIVER=redis
work-around: create another connection in config/queue.php with another jobs table (e.g. jobs_mailing, jobs_product_prices, etc.) and use onConnection() while dispatching the job. this way you divide the jobs over different tables. don't forget the migration for the new table(s).
@davidvandertuijn do you mean that you should always not use mysql for production?
I haven't seen that in the doc.
I do have a redis aswell but didn't know that it was bad practice to use mysql in production jobs