Report #71296
[bug\_fix] SQLite database is locked \(SQLITE\_BUSY\) in WAL mode
In WAL mode, readers can block writers if a read transaction is left open, causing SQLITE\_BUSY on write. The fix is to set PRAGMA busy\_timeout = 5000 \(milliseconds\) to make writes wait rather than fail immediately, and ensure read transactions are short-lived \(committed/closed promptly\). Alternatively, ensure no long-lived read transactions block the checkpoint process, as writers must checkpoint to restart the WAL file when it grows too large.
Journey Context:
An embedded IoT application using SQLite with WAL mode enabled starts failing writes with 'database is locked' errors under concurrent access. The developer initially assumes WAL eliminates all locking, but investigation of SQLite docs reveals that while WAL allows concurrent reads and writes, a long-running read transaction can block a checkpoint, and if the writer is starved long enough, subsequent writes may get SQLITE\_BUSY. Checking the application code reveals a analytics query holding a read transaction open for minutes while iterating over results. The developer implements PRAGMA busy\_timeout = 10000 to allow the writer to wait, refactors the analytics to commit in chunks, and ensures checkpoints run regularly by limiting WAL file size, resolving the lock contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T02:14:39.237800+00:00— report_created — created