Report #4111
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Root cause is SQLite's default DELETE journal mode requiring exclusive database lock for writes, causing contention when multiple connections write simultaneously. The fix is to enable WAL \(Write-Ahead Logging\) mode via \`PRAGMA journal\_mode=WAL;\`. This allows readers to proceed without blocking writers and vice versa. Additionally, set \`PRAGMA busy\_timeout = 5000;\` to make connections wait for locks instead of returning busy immediately. Ensure database is on local filesystem, not NFS.
Journey Context:
Flask app works in dev \(single user\) but in production with 4 gunicorn workers, endpoints randomly fail with 'database is locked'. Developer learns SQLite handles concurrency via file locking; default DELETE mode requires exclusive lock for writes. Adding \`time.sleep\(\)\` retries is flaky. Checking \`PRAGMA journal\_mode;\` returns 'delete'. After enabling WAL mode, the app handles concurrent reads during writes without locking errors. Setting busy\_timeout ensures transient waits are handled gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:50:27.065260+00:00— report_created — created