Report #12296
[bug\_fix] SQLite3::BusyException: database is locked \(SQLITE\_BUSY\)
Execute PRAGMA busy\_timeout = 5000 \(milliseconds\) immediately after opening the database to force SQLite to retry rather than fail immediately; additionally ensure WAL \(Write-Ahead Logging\) mode is enabled via PRAGMA journal\_mode=WAL to allow concurrent reads during writes.
Journey Context:
Building an Electron desktop app with SQLite for local storage. In development with a single user, everything worked. After release, users reported random 'database is locked' errors when saving settings while background sync ran. Debugging revealed that SQLite's default busy timeout is 0, meaning it returns SQLITE\_BUSY immediately if the database is locked by another connection. The background sync thread held a write lock for 50ms while the UI thread tried to update a setting. By setting PRAGMA busy\_timeout=5000, the UI thread now sleeps and retries for up to 5 seconds before throwing, which is sufficient for the background task to complete. Enabling WAL mode further reduced contention by allowing readers to proceed without blocking on writers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:40:55.983715+00:00— report_created — created