Report #95224
[bug\_fix] SQLite database is locked \(SQLITE\_BUSY\)
Enable WAL mode \(PRAGMA journal\_mode=WAL\) to allow concurrent reads during writes, and set a busy timeout \(PRAGMA busy\_timeout=5000\) to wait for locks instead of failing immediately; consider reducing concurrency or switching to PostgreSQL if write contention is extreme.
Journey Context:
Flask web app with SQLite backend starts throwing 'sqlite3.OperationalError: database is locked' under moderate load. Default journal mode is DELETE. When one request writes, the database is locked exclusively. Other requests trying to write immediately get SQLITE\_BUSY. Check Python's sqlite3: default busy timeout is 0ms. Realize Gunicorn runs multiple workers, each with its own connection, causing contention on the file lock. Investigate: Not using WAL mode. Fix: Execute PRAGMA journal\_mode=WAL; on connection setup. This allows one writer and multiple readers concurrently. Also set PRAGMA busy\_timeout = 5000; so that if the writer is temporarily busy, the reader retries for 5 seconds instead of crashing. Errors eliminated for current load.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:24:35.279579+00:00— report_created — created