SQLite Forum

Unexepected commit result with two threads application
Login
You should set a timeout on each connection.  This will allow SQLite to handle SQLITE_BUSY internally, not bothering your software but handling the wait-and-retry loop itself.  Two threads accessing the same database very quickly will definitely block each other occasionally and setting a timeout is a fast and simple way to solve the problem.

For testing purposes I recommend you set a timeout on each connection to a minute.  This will allow you to figure out what your software is doing.  Once you have a working system you might bring the value down to five seconds or so.

<https://sqlite.org/c3ref/busy_timeout.html>