fix(quartz/sqlite): set busy_timeout to deflake reader+writer races

Without busy_timeout SQLite returns SQLITE_BUSY immediately when
BEGIN IMMEDIATE can't acquire a lock — e.g. during a WAL
auto-checkpoint or a reader briefly upgrading its snapshot — instead
of retrying. ParallelInsertTest's reader+writer test hit this ~10%
of runs. 5s matches Room's default and adds no overhead in the
uncontended case.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vitor Pamplona
2026-05-18 20:02:35 -04:00
co-authored by Claude Opus 4.7
parent 68c081602f
commit ab3d1dd7e5
@@ -106,6 +106,13 @@ class SQLiteEventStore(
// The DB can be corrupted if the OS shuts down before
// sync, which generally doesn't happen on Android.
db.execSQL("PRAGMA synchronous = OFF;")
// Without busy_timeout, BEGIN IMMEDIATE returns SQLITE_BUSY
// the instant another connection holds a conflicting lock —
// e.g. a WAL auto-checkpoint or a reader transiently
// upgrading its snapshot. With it, SQLite retries internally
// for up to N ms before giving up. Matches Room's default.
db.execSQL("PRAGMA busy_timeout = 5000;")
},
onMigrate = { db ->
val currentVersion = getUserVersion(db)