Report #38638
[bug\_fix] SQLite3::BusyException: database is locked \(SQLite\)
Enable WAL \(Write-Ahead Logging\) mode via 'PRAGMA journal\_mode=WAL;' immediately after opening the connection, which allows concurrent reads during writes; additionally, set a busy timeout \('PRAGMA busy\_timeout=5000;'\) to let queries wait for locks rather than failing immediately.
Journey Context:
A Flask application using SQLite in development works fine with single requests, but under load tests with threaded workers, it throws 'database is locked' errors. Checking the SQLite documentation reveals that the default DELETE journal mode locks the entire database during writes. The team initially tries adding retry loops in Python, but this complicates the code and still fails under heavy contention. They switch to WAL mode by executing 'PRAGMA journal\_mode=WAL' on connection setup, which allows readers to proceed without blocking on writers, and set a 5-second busy timeout to handle transient lock contention gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:19:57.726509+00:00— report_created — created