Repository navigation
Conversation
…sy_timeout first, WAL retry, immediate write transactions #1226 Signed-off-by: Nik Cubrilovic <[email protected]>
…L polynomial ReDoS) #1226 Signed-off-by: Nik Cubrilovic <[email protected]>
#1226 Signed-off-by: Nik Cubrilovic <[email protected]>
This was referenced Oct 30, 2026
Contributor
Author
|
Landed in v0.0.143 as nik |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1226
Root cause
Reproduced with a multi-process test before any change. Two causes, both on a fresh connection under contention:
PRAGMA journal_mode = WALon a file other processes are creating returns SQLITE_BUSY at once. SQLite does not run the busy handler for that lock, so nobusy_timeoutvalue helps (and it was set after this pragma anyway).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 (SQLiteStorageproject db,ContentStore,LinkCacheStorage):openSqlite(path):busy_timeoutis 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.BEGINsites inSQLiteStorage(migrations, script records) areBEGIN IMMEDIATE.StorageErrorreads that suffix, so the user-facing message says which file stayed locked and for how long.docs/configuration/storage.mdxstates 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)" atinit). 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.squirrel auditruns 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 validatepasses. 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 auditcheck (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.