Report #43985
[bug\_fix] database is locked \(SQLITE\_BUSY\)
Enable WAL \(Write-Ahead Logging\) mode via PRAGMA journal\_mode=WAL, or set PRAGMA busy\_timeout=5000 to allow writers to wait instead of failing immediately.
Journey Context:
An Electron desktop app randomly crashes with SQLiteException: database is locked during user data saves. Investigation shows the main thread performs writes while a background sync thread performs reads on the same database connection. Default SQLite uses DELETE journal mode, which requires an EXCLUSIVE lock during commit, blocking all readers. When the background thread holds a read lock \(SHARED\) and the main thread tries to upgrade to EXCLUSIVE, it fails immediately with SQLITE\_BUSY. The debugging rabbit hole involves checking file locks with lsof and realizing the -shm and -wal files don't exist because WAL mode is disabled. The fix requires executing PRAGMA journal\_mode=WAL immediately after opening the database, which allows readers to proceed without blocking writers and eliminates the busy errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T04:18:04.270236+00:00— report_created — created