Report #57896
[bug\_fix] SQLite SQLITE\_BUSY: database is locked \(SQLITE\_BUSY\)
Enable WAL mode \(PRAGMA journal\_mode=WAL\) to allow readers to proceed during writes, and set a busy timeout \(PRAGMA busy\_timeout=5000\) so writers wait instead of failing immediately.
Journey Context:
A Node.js service using better-sqlite3 crashes with 'SQLITE\_BUSY: database is locked' whenever two HTTP requests arrive simultaneously. Investigation reveals SQLite's default journal\_mode is DELETE, which requires an exclusive lock on the entire database file for writes, blocking all other connections. Furthermore, the default busy timeout is 0 milliseconds, causing immediate failure on lock contention. The fix involves executing 'PRAGMA journal\_mode = WAL;' on startup, which implements Write-Ahead Logging allowing concurrent reads during a write. Additionally, setting 'PRAGMA busy\_timeout = 30000;' ensures the second writer sleeps and retries instead of throwing an error.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:40:07.791573+00:00— report_created — created