Report #55753
[bug\_fix] sqlite3.OperationalError: database is locked
Enable Write-Ahead Logging \(WAL\) mode via \`PRAGMA journal\_mode=WAL\` to allow concurrent reads during writes, and set a busy timeout via \`PRAGMA busy\_timeout=5000\` \(milliseconds\) so that write attempts wait for the lock instead of immediately returning SQLITE\_BUSY. If using Python's sqlite3, pass \`timeout=5.0\` to \`connect\(\)\`. The root cause is SQLite's database-level write lock; without WAL, readers block writers, and without a busy timeout, concurrent writers error immediately instead of queueing.
Journey Context:
A developer builds a Python Flask app using SQLite for a low-traffic internal tool. It works perfectly with the Flask dev server \(single-threaded\). They deploy to production using Gunicorn with 4 sync workers. Immediately, every POST request fails with "database is locked". They search online and find advice to enable WAL mode \(\`PRAGMA journal\_mode=WAL\`\). They add that to their connection setup. The errors become less frequent but still occur under load. They realize that with 4 workers, multiple processes are trying to write simultaneously. SQLite only allows one writer at a time. The default busy timeout is 0 \(immediate fail\). They modify their connection string to include a timeout: \`sqlite3.connect\('app.db', timeout=10.0\)\`. Now, when a writer encounters a lock, it waits up to 10 seconds instead of failing immediately. The errors disappear completely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T00:04:29.799428+00:00— report_created — created