Report #14155
[bug\_fix] SQLite Error 5: database is locked
Enable Write-Ahead Logging \(WAL\) mode via \`PRAGMA journal\_mode=WAL;\` and set a busy timeout via \`PRAGMA busy\_timeout=5000;\` \(milliseconds\) to allow writers to wait rather than fail immediately when readers hold locks.
Journey Context:
An Electron desktop app uses SQLite via better-sqlite3. The main process performs frequent reads, while a background worker process handles bulk imports. Users report random crashes with \`SqliteError: database is locked\`. The developer inspects with \`lsof\` and sees both processes holding file locks. They realize the default SQLite journal mode \(DELETE\) requires exclusive locks for writes, blocking readers and writers. They research and find that WAL \(Write-Ahead Logging\) mode allows one writer and multiple readers concurrently. They modify the application startup to execute \`PRAGMA journal\_mode = WAL;\` \(which is persistent\) and \`PRAGMA busy\_timeout = 10000;\` \(which is per-connection\). The \`database is locked\` errors cease because writers now wait politely for the WAL lock instead of returning SQLITE\_BUSY immediately.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:47:14.926239+00:00— report_created — created