Report #50846
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Enable Write-Ahead Logging \(WAL\) mode by executing PRAGMA journal\_mode=WAL; this allows readers to proceed without blocking writers and vice versa. Additionally, set a busy timeout handler using PRAGMA busy\_timeout=5000; \(milliseconds\) so that SQLite retries the operation if the database is busy rather than returning SQLITE\_BUSY immediately.
Journey Context:
Mobile or desktop app using SQLite experiences random 'database is locked' crashes when multiple threads or processes access the database. Investigation shows one thread is writing while another tries to read or write, resulting in SQLITE\_BUSY. The initial attempt to fix by adding retries in application code is complex and error-prone. The rabbit hole leads to understanding SQLite's locking model: in the default DELETE journal mode, a writer gets an exclusive lock on the entire database file, blocking all others. The proper fix is enabling WAL mode, which implements multi-version concurrency control \(MVCC\) for SQLite, allowing concurrent reads during writes. Adding a busy timeout ensures transient locks are handled gracefully without application-level retry logic.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T15:49:46.494794+00:00— report_created — created