Report #5373
[bug\_fix] SQLite error 5 \(SQLITE\_BUSY\): database is locked
Enable WAL \(Write-Ahead Logging\) mode via PRAGMA journal\_mode=WAL; and set a busy timeout via PRAGMA busy\_timeout=5000; \(milliseconds\). Root cause: SQLite's default DELETE journal mode locks the entire database file for the duration of any write, blocking all readers and other writers; without WAL, concurrent access results in immediate SQLITE\_BUSY errors or writer starvation.
Journey Context:
You ship an Electron app storing user data in SQLite. Users report intermittent "database is locked" errors when autosave triggers while a background sync reads the database. You reproduce by opening two SQLite CLI sessions: one begins a transaction with BEGIN IMMEDIATE \(reserved lock\), the other tries to write—immediately gets SQLITE\_BUSY. You check the journal mode: PRAGMA journal\_mode; returns "delete". You research and learn that in DELETE mode, the writer must obtain a reserved lock and then an exclusive lock, blocking all other connections for the duration of the write. You find the WAL mode documentation: it allows readers to read from the last committed snapshot while a writer appends to the WAL file, achieving true concurrency between one writer and many readers. You execute PRAGMA journal\_mode=WAL; \(this persists to the -wal file\). You also add PRAGMA busy\_timeout=3000; so that if two writers collide, the second waits briefly instead of failing immediately. After redeploying, the "database is locked" errors vanish because WAL mode isolates the read transaction from the writer's lock, and the busy timeout handles the rare writer-writer contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T21:09:58.252047+00:00— report_created — created