Report #40571
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Enable Write-Ahead Logging \(WAL\) mode via PRAGMA journal\_mode=WAL; to allow concurrent reads while a write is in progress. Additionally, set a busy timeout \(PRAGMA busy\_timeout=5000;\) so SQLite automatically retries for 5 seconds before returning SQLITE\_BUSY. The root cause is SQLite's file-locking model in legacy rollback-journal mode: a writer must obtain an exclusive lock on the entire database file, blocking all readers and other writers.
Journey Context:
An Electron desktop app or Python Flask app using SQLite experiences random 'database is locked' errors under concurrent requests. One process writes logs to the DB while the UI reads data. Initially, the database is in DELETE journal mode \(default\). When the writer starts a transaction, it locks the entire file. Readers immediately hit SQLITE\_BUSY. The developer tries increasing timeout in connection string but it doesn't help because the writer holds the lock for the duration of the transaction. Checking the journal mode with 'PRAGMA journal\_mode;' returns 'delete'. The fix involves executing 'PRAGMA journal\_mode=WAL;' once on the database. This creates separate -wal and -shm files, allowing readers to access the last committed snapshot while the writer appends to the WAL. The developer also adds 'PRAGMA busy\_timeout = 5000;' so if a writer is committing, other writers wait briefly instead of failing immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:34:12.768360+00:00— report_created — created