fix(db): survive concurrent first open of a new database #26

Merged
shree-mulay merged 1 commit from fix/db-open-race into main 2026-11-10 01:49:57 -06:00
Owner

Two servers opening the same new database at once could crash one of them with SQLITE_BUSY on PRAGMA journal_mode = WAL (the busy timeout does not cover that switch). Reproduced on main: 4-5 failures per 30 runs of the existing two-process test.

  • Skip the switch when already WAL; otherwise retry on BUSY with bounded backoff (about 5 s), then fail with an error naming the path.
  • Open into a local handle and cache it only after pragmas and migrations succeed, so a failed open is retried instead of leaving an unmigrated connection.
  • Tests: four-process concurrent open, clear locked-database error, failure-then-retry.

No migration, schema, tool or signature change.

Validation: race test 0/50 failures and schema suite 0/40 after the fix; audit, typecheck, lint, 495 tests x3, build, package smoke, diff --check.

Two servers opening the same new database at once could crash one of them with `SQLITE_BUSY` on `PRAGMA journal_mode = WAL` (the busy timeout does not cover that switch). Reproduced on main: 4-5 failures per 30 runs of the existing two-process test. - Skip the switch when already WAL; otherwise retry on BUSY with bounded backoff (about 5 s), then fail with an error naming the path. - Open into a local handle and cache it only after pragmas and migrations succeed, so a failed open is retried instead of leaving an unmigrated connection. - Tests: four-process concurrent open, clear locked-database error, failure-then-retry. No migration, schema, tool or signature change. Validation: race test 0/50 failures and schema suite 0/40 after the fix; audit, typecheck, lint, 495 tests x3, build, package smoke, diff --check.
fix(db): survive concurrent first open and never cache a failed connection
All checks were successful
Forgejo Actions CI / node24 (pull_request) Successful in 13s
Forgejo Actions CI / node22 (pull_request) Successful in 14s
Security Scanning / security (pull_request) Successful in 24s
Forgejo Actions CI / bun (pull_request) Successful in 1m5s
Forgejo Actions CI / package_smoke (pull_request) Successful in 26s
Forgejo Actions CI / ci (pull_request) Successful in 1s
cc24ca6a53
Agent-Session: ses_2dc63dfbaffeHXzDMI4t5MZiSm
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thekidneyexperts/autoresearch-mcp!26
No description provided.