Report #47278
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Set PRAGMA busy\_timeout = 5000 \(milliseconds\) immediately after opening the SQLite connection to automatically retry when the database is busy, and ensure WAL mode is enabled \(PRAGMA journal\_mode = WAL\) to allow concurrent reads during writes.
Journey Context:
Your Python Flask app using SQLite suddenly starts throwing sqlite3.OperationalError: database is locked under moderate load. You check the file and see a -wal journal file growing. Investigating with lsof shows one long-running SELECT statement holding a shared lock while a write tries to acquire an exclusive lock. The default busy\_timeout is 0, meaning SQLite returns SQLITE\_BUSY immediately instead of waiting. You add PRAGMA busy\_timeout = 5000 to your connection setup and enable WAL mode. Now when a write encounters a locked database, it waits up to 5 seconds for the reader to finish rather than failing immediately. The errors disappear and read performance improves because WAL mode allows readers to proceed without blocking on writers, while busy\_timeout provides grace for transient contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T09:50:37.062882+00:00— report_created — created