Report #99152
[bug\_fix] SQLite database is locked
Enable WAL mode \(PRAGMA journal\_mode=WAL\) so readers do not block writers and writers do not block readers. If the lock still occurs, increase the busy timeout to allow SQLite to retry instead of failing immediately \(PRAGMA busy\_timeout=5000\). Keep transactions short, avoid long reads inside a write transaction, and never hold a write transaction while doing network I/O. If multiple processes write, serialize writes through a single writer connection or use a connection pool with one writer. In Python, use the same sqlite3 connection object for all writes in a thread; do not open and close a new connection per write.
Journey Context:
A small Flask app using sqlite3 in a Docker container started returning sqlite3.OperationalError: database is locked under concurrent POST requests. The developer first tried setting timeout=10 in connect\(\), which only masked some failures. They then noticed the database was in DELETE journal mode and a long-running SELECT inside a request handler was holding a SHARED lock while another request tried to COMMIT. They enabled WAL with PRAGMA journal\_mode=WAL once at startup, set PRAGMA busy\_timeout=5000, and split reads and writes so the writer connection was the only one committing. Lock errors disappeared entirely because WAL allows concurrent reads during a write and the busy timeout gave competing writers a fair retry window.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-29T04:39:03.782872+00:00— report_created — created