Report #59012
[bug\_fix] SQLite database is locked \(SQLITE\_BUSY\)
Enable WAL \(Write-Ahead Logging\) mode via PRAGMA journal\_mode=WAL to allow concurrent reads during writes, and set a busy timeout \(PRAGMA busy\_timeout = 5000\) to allow connections to wait for locks rather than failing immediately.
Journey Context:
A Flask application with multiple gunicorn workers is deployed. Reads work fine, but any write operation intermittently throws 'database is locked'. Checking the SQLite documentation reveals that the default journal\_mode=DELETE uses exclusive locking for writes, blocking all readers and other writers. The application is trying to write from multiple threads/processes simultaneously. Initial attempts to synchronize via Python threading locks fail because multiple workers are separate processes. The solution involves executing PRAGMA journal\_mode=WAL immediately on connection creation, which allows readers to proceed without blocking during writes. Additionally, setting PRAGMA busy\_timeout=5000 ensures that if a lock is held, the connection waits up to 5 seconds rather than immediately returning SQLITE\_BUSY.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:32:22.941054+00:00— report_created — created