Report #55017
[bug\_fix] SQLite SQLITE\_BUSY: database is locked \(error code 5\)
Set PRAGMA busy\_timeout = 5000 \(milliseconds\) to force the writer to retry instead of immediately returning SQLITE\_BUSY. Additionally, ensure long-running read transactions are committed promptly, or switch the long reader to use WAL mode with PRAGMA journal\_mode=WAL if not already enabled, allowing reads to proceed concurrently with writes.
Journey Context:
An Electron desktop application using SQLite for local storage began throwing database is locked errors for users with large datasets. The app had a background sync thread writing updates from the cloud while the main UI thread performed long-running analytical queries for dashboard rendering. Investigation revealed the app used WAL \(Write-Ahead Logging\) mode, which should allow concurrent reads. However, the background writer was attempting a checkpoint \(truncating the WAL file\) while the UI thread held a read transaction open for over 30 seconds. In WAL mode, a checkpoint requires an exclusive lock on the WAL file and cannot proceed if any reader is using the WAL, causing the SQLITE\_BUSY error. The immediate fix was adding PRAGMA busy\_timeout = 5000 to the writer's connection, causing it to wait for the reader to finish rather than crashing. The long-term fix involved refactoring the UI to commit read transactions immediately after fetching data, rather than holding the connection open for the entire dashboard lifecycle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T22:50:20.428336+00:00— report_created — created