Skip to content

fix(crawler,cli): parallel audits no longer fail with SQLite busy #1226 - #1302

Closed
nc9 wants to merge 3 commits into
mainfrom
fix/1226-sqlite-busy
Closed

nc9 wants to merge 3 commits into
mainfrom
fix/1226-sqlite-busy

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1226

Root cause

Reproduced with a multi-process test before any change. Two causes, both on a fresh connection under contention:

  1. PRAGMA journal_mode = WAL on a file other processes are creating returns SQLITE_BUSY at once. SQLite does not run the busy handler for that lock, so no busy_timeout value helps (and it was set after this pragma anyway).
  2. Write transactions were deferred (db.transaction(), BEGIN): read under a snapshot, then fail with SQLITE_BUSY_SNAPSHOT when they upgrade after another process committed. The busy handler never retries that.

Fix (at the storage layer, one helper)

New packages/crawler/src/storage/sqlite-open.ts (@squirrelscan/crawler/sqlite-open), used by all three shared stores (SQLiteStorage project db, ContentStore, LinkCacheStorage):

  • openSqlite(path): busy_timeout is the first statement on the connection; transaction() takes the write lock up front (.immediate); busy errors get (database file: <path>, waited <ms> ms) appended.
  • enableWal(db): retries the WAL switch with a short jittered pause until the timeout is spent.
  • The two raw BEGIN sites in SQLiteStorage (migrations, script records) are BEGIN IMMEDIATE.
  • StorageError reads that suffix, so the user-facing message says which file stayed locked and for how long.
  • Docs: "Running several audits at once" in docs/configuration/storage.mdx states the guarantee and its limit (same-site audits still contend for one project db and queue).

Tests (failing first)

  • apps/cli/tests/crawler/concurrent-processes-1226.test.ts: 8 real processes released together by a start file, each opening the content store, link cache and one shared project db and writing, 3 rounds; every process must finish. Failed on main in the first round ("busy (locked)" at init). No timing assertions.
  • packages/crawler/tests/sqlite-open-1226.test.ts: timeout is first; a lock past the timeout names file and wait; a read-then-write transaction waits for another process's write lock and commits; enableWal.
  • Verified by hand with the issue's repro: 10 concurrent squirrel audit runs of 10 different local sites, 3 rounds, shared HOME: 30 of 30 exit 0 with reports, no busy errors.

Gates: apps/cli format, lint, tsgo; tsgo in crawler and core-contracts; 91 related tests pass; make validate passes. Skill (squirrelscan/skills): no change needed. CHANGELOG under ## [Unreleased] / Fixed.

Scope note: the multi-process test is store level (content store, link cache and project db, 8 processes x 3 rounds). The real squirrel audit check (10 concurrent audits of 10 local sites, 3 rounds, 30 of 30 reports) was run by hand, not committed as a test, because it takes minutes and many processes.

…sy_timeout first, WAL retry, immediate write transactions #1226

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.143 as b8018fbc 14fee0e5 546e0983 via #1341. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.143. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Concurrent squirrel audit processes fail with 'SQLite database is busy (locked)'

2 participants