Report #8535
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Set \`PRAGMA busy\_timeout = 5000;\` \(milliseconds\) on every database connection to make SQLite wait for locks instead of returning immediately. For high concurrency, enable Write-Ahead Logging \(WAL\) mode with \`PRAGMA journal\_mode=WAL;\`, which allows readers to proceed without blocking writers and vice versa \(though writers still serialize\).
Journey Context:
A developer deploys a Python Flask app using SQLite for an internal tool. Under light load it works, but when two users submit forms simultaneously, one gets "sqlite3.OperationalError: database is locked". The developer finds suggestions to increase the timeout in the connection string \(e.g., \`timeout=10\`\). They try this but still see errors under load. They check \`PRAGMA journal\_mode;\` and find it's DELETE \(default\). In DELETE mode, a writer gets an EXCLUSIVE lock on the entire database. The default busy\_timeout is 0, so it returns immediately if locked. The developer switches to WAL mode: \`PRAGMA journal\_mode=WAL;\`. This allows one writer to proceed while readers read the WAL. However, two writers still conflict, so they set \`PRAGMA busy\_timeout = 30000;\` to make the second writer wait up to 30 seconds. After this, "database is locked" errors disappear.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:44:52.940934+00:00— report_created — created