Report #17749
[bug\_fix] database is locked \(SQLITE\_BUSY or SQLITE\_LOCKED\) in SQLite
Enable Write-Ahead Logging \(WAL\) mode via 'PRAGMA journal\_mode=WAL;' which allows concurrent reads during writes. Set a busy timeout handler \(PRAGMA busy\_timeout=5000\) so SQLite retries rather than returning BUSY immediately. For writers, use 'BEGIN IMMEDIATE' to acquire the write lock upfront and fail fast if busy, rather than failing at COMMIT. Root cause: SQLite's default DELETE journal mode uses locks that block readers during writes; without busy handlers, any contention returns an error immediately.
Journey Context:
A desktop analytics application uses SQLite for local storage. When the sync engine writes bulk updates, the UI thread queries for charts and crashes with 'database is locked'. The developer initially adds retry loops in Python, but the UI still stutters. Checking SQLite docs, they learn about WAL mode which allows 'single writer, many readers' concurrently. They execute 'PRAGMA journal\_mode=WAL;' on connection setup. They also set 'PRAGMA busy\_timeout=3000' so writers wait briefly instead of erroring. They change the sync worker to use 'BEGIN IMMEDIATE' so it fails early if another writer is active, preventing partial work. The locked errors disappear and the UI remains responsive during heavy writes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T06:18:31.917360+00:00— report_created — created