Report #56437
[bug\_fix] SQLite database is locked \(SQLITE\_BUSY\)
Enable WAL mode \(PRAGMA journal\_mode = WAL\) and set busy timeout to 5000ms \(PRAGMA busy\_timeout = 5000\) to allow blocking with retry instead of immediate failure.
Journey Context:
React Native app displays "database is locked" errors during background sync. Investigation reveals main thread performs long-running SELECT queries while background thread attempts bulk INSERTs. The rabbit hole involves understanding SQLite's file-locking mechanism on POSIX systems using advisory locks, discovering the app runs on WAL mode but with default busy\_timeout=0 causing immediate SQLITE\_BUSY returns, and realizing long-running readers prevent checkpointing causing WAL file growth that exacerbates locking. The fix works because busy\_timeout instructs SQLite to retry locks with exponential backoff up to 5 seconds, allowing transient contention to resolve, while WAL mode allows concurrent readers with a single writer, eliminating the writer-starvation problem inherent in rollback-journal mode.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T01:13:20.922408+00:00— report_created — created