Report #9936
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Set a busy timeout via PRAGMA busy\_timeout = 5000; \(milliseconds\) or the sqlite3\_busy\_timeout\(\) API so the connection waits for locks to clear instead of returning SQLITE\_BUSY immediately. Root cause: SQLite uses file-level locking; when one connection holds a RESERVED or EXCLUSIVE lock during a write, another writer gets BUSY instantly unless configured to wait.
Journey Context:
You deploy a Python Flask app using SQLite in WAL mode. Under concurrent POST requests from 20 workers, you get intermittent sqlite3.OperationalError: database is locked. You attach strace and see flock returning EAGAIN on the database file. You realize two threads are trying to commit simultaneously; one holds the lock, the other gets SQLITE\_BUSY immediately because the default busy timeout is 0. You add conn.execute\('PRAGMA busy\_timeout = 30000'\) immediately after opening each connection. The database locked errors stop; writers now queue gracefully, waiting up to 30 seconds for the lock.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:23:40.065508+00:00— report_created — created