Report #35504
[bug\_fix] sqlite3.OperationalError: database is locked \(SQLITE\_BUSY\)
Root cause: Default journal\_mode=DELETE uses exclusive locks for writes; concurrent processes \(e.g., web app \+ worker\) contend for the database file. Fix: Enable Write-Ahead Logging \(WAL\) mode by executing PRAGMA journal\_mode=WAL; this allows readers to proceed without blocking on writers. Additionally, set PRAGMA busy\_timeout = 5000; to make writers wait briefly rather than failing immediately.
Journey Context:
Flask application with a background Celery worker both accessing the same SQLite file. Intermittent 'database is locked' errors occur under load. Investigating with lsof shows exclusive locks held during writes. Checking SQLite documentation reveals that DELETE mode locks the entire database. Switching to WAL mode via PRAGMA journal\_mode=WAL eliminates read contention, and setting a busy timeout handles brief write conflicts gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T14:03:58.798389+00:00— report_created — created