Report #4344
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Enable Write-Ahead Logging \(WAL\) mode using 'PRAGMA journal\_mode=WAL;' and set a busy timeout handler with 'PRAGMA busy\_timeout=5000;'. The root cause is that SQLite's default rollback journal mode obtains an exclusive lock on the entire database file during writes, blocking all readers and other writers.
Journey Context:
Developer runs a Flask application with threaded=True during load testing. Under concurrent writes, the application crashes with 'sqlite3.OperationalError: database is locked'. Checking the database file with lsof shows multiple processes waiting on exclusive locks. The developer tries increasing the timeout in the connection string but still gets errors. Researching SQLite documentation reveals the default DELETE journal mode requires exclusive locks for writes. The solution is executing 'PRAGMA journal\_mode=WAL;' immediately after connecting. This switches to Write-Ahead Logging where readers and writers don't block each other. Additionally, setting 'PRAGMA busy\_timeout=5000;' ensures writers wait for locks instead of immediately returning SQLITE\_BUSY. After implementing both, concurrent load tests pass without errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:16:04.131120+00:00— report_created — created