Report #76086
[bug\_fix] database is locked \(SQLITE\_BUSY, code 5\)
Enable WAL mode \(PRAGMA journal\_mode=WAL\) and set a busy timeout \(PRAGMA busy\_timeout=5000\). Root cause: Default rollback journal \(DELETE mode\) requires exclusive locks for writes; readers block writers. Without a busy timeout, SQLite returns immediately if the lock is held.
Journey Context:
An Electron app uses SQLite for local user data. In development with a single user, everything works. In production, users report 'database is locked' errors when clicking 'Save' while a background sync reads data. The developer discovers that the default journal\_mode=DELETE creates a 'hot journal' and requires exclusive database locks during writes. When the background read transaction holds a SHARED lock, the write cannot proceed. The developer initially tries catching SQLITE\_BUSY and retrying manually, but races persist. The correct investigation involves running PRAGMA journal\_mode; which returns 'delete'. Switching to WAL \(Write-Ahead Logging\) mode via PRAGMA journal\_mode=WAL; allows readers to not block writers and vice versa. Additionally, setting PRAGMA busy\_timeout=5000 ensures that if a lock is momentarily held, SQLite waits up to 5 seconds rather than returning SQLITE\_BUSY immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T10:18:14.813731+00:00— report_created — created