Report #100098
[bug\_fix] SQLITE\_BUSY: database is locked
Enable WAL mode with PRAGMA journal\_mode=WAL, set PRAGMA busy\_timeout=5000 \(or pass timeout=5 to sqlite3.connect\), keep write transactions short, and do not share a single connection across threads.
Journey Context:
A telemetry daemon written in Python collected metrics from multiple threads and wrote them into a single SQLite file. Under load it started raising sqlite3.OperationalError: database is locked. The default rollback-journal mode requires an EXCLUSIVE lock on the whole database file for every write, so when one thread held a write transaction, any other thread that tried to write immediately got SQLITE\_BUSY. The fix was to open each connection with timeout=5.0 and execute PRAGMA journal\_mode=WAL on startup. WAL mode moves writes to a separate log file, allowing readers to proceed concurrently with a writer and serializing writers more gracefully. busy\_timeout makes SQLite wait for the lock instead of failing instantly. After the change, lock errors dropped to zero because the database no longer needed an exclusive file lock for every read/write cycle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-01T04:38:57.360293+00:00— report_created — created