Report #10506
[bug\_fix] SQLiteException: database is locked \(SQLITE\_BUSY\)
Enable Write-Ahead Logging \(WAL\) mode via PRAGMA journal\_mode=WAL; set a busy timeout handler using PRAGMA busy\_timeout=5000 \(milliseconds\) to allow waiting for locks rather than immediate failure.
Journey Context:
Desktop application using SQLite for local storage crashes when users perform rapid save operations while background sync reads data. The error "database is locked" appears intermittently on Windows and macOS. Developer initially suspects file permissions but realizes SQLite uses file locking for concurrency. Checking PRAGMA journal\_mode; returns "delete" \(default\). In DELETE mode, a writer gets an exclusive lock on the entire database file, blocking readers and other writers. If another thread tries to write during this, it gets SQLITE\_BUSY immediately because the default busy timeout is 0. Developer switches to WAL mode \(PRAGMA journal\_mode=WAL\), which allows readers to continue using old snapshots while writers append to the WAL file. They also set PRAGMA busy\_timeout=5000 so that if a lock is held briefly, the second writer waits up to 5 seconds instead of failing immediately. The rapid-save crashes stop because WAL provides concurrency and the timeout handles momentary contention.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:51:18.234506+00:00— report_created — created