OrakMoya's avatar

Database locked errors with multiple queue workers and SQLite

I have two queue workers listening on the same queue thats using SQLite. When they both get a lot of short tasks I start seeing database locked errors in logs. This causes the job to have a failed state and be retried even if it was successful. This is a bit problematic since the jobs deal with files and executing them again fails with a file not found.

Here is a relevant log line:

0 likes
5 replies
Tray2's avatar

That is normal behavior, it wouldn't matter which database you would use. You need to make sure not to make sure that they don't pick the same rows.

1 like
OrakMoya's avatar

Doesnt seem like it because the error is trying to update a status of a job and the error doesnt happen when using MySQL (or, MariaDB).

I didn't even have the jobs table in the same sqlite database file. As part of an attempted fix, I created a new DB connection in a SQLite database that only contained jobs, but it still failed with a database locked when trying to update it (see logline above, the "jobs_db" database only contains jobs).

The jobs themselves dont update the same rows, I'm sure of that. Either way, the error isnt thrown by the job. It seems to be thrown by Illuminate\\Queue\\DatabaseQueue->markJobAsReserved()

Tray2's avatar

@OrakMoya If I remember correctly, the jobs table uses two indexes, and it might be that too frequent updates to the table causes the indexes to lock the records.

This was the case in another thread here a few years back.

OrakMoya's avatar

@Tray2 So is there a way to fix the busy timeouts? I tried changing the busy_timeout parameter in database.php, enabling WAL and moving jobs to redis but some jobs are in a batch and that table also experiences this issue.

Tray2's avatar

@OrakMoya Don't know. I would try to add a little sleep between each iteration though.

Please or to participate in this conversation.