Skip to content

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

Closed

Description

@nc9

Observed on squirrel v0.0.138; the relevant code is unchanged on current main.

Problem

Running several squirrel audit processes at once (4 to 10 audits of different sites on one machine) makes a fraction of them fail and write no report:

Audit failed: Storage error during read: SQLite database is busy (locked). Another squirrelscan crawl/report/analyze command may be running in parallel. Wait for it to finish and retry.

The audited sites are different, so the only thing the processes share is the machine-wide store ~/.squirrel/content-store.db (and the link cache next to it). Auditing different sites in parallel is a normal batch pattern and should not fail.

Repro: for i in 1 2 3 4 5 6 7 8 9 10; do squirrel audit https://site$i.example.com --max-pages 30 -f json -o out$i.json & done; wait, then count the processes that exit non-zero with the message above.

Where to look

The stores already set PRAGMA busy_timeout = 15000, but in apps/cli/src/crawler/storage/content-store.ts (getDb) and packages/crawler/src/storage/sqlite.ts (init) the timeout is set after PRAGMA journal_mode = WAL, wal_autocheckpoint and synchronous, and before the schema runs. SQLite's default busy timeout is 0, so the very first statements on a fresh connection (the WAL switch and the first schema statements, which need a lock) fail immediately with SQLITE_BUSY when another process holds the write lock. Candidates to check:

  1. Set busy_timeout first, before journal_mode = WAL.
  2. Write transactions begun as deferred BEGIN that later upgrade to a write lock fail at once under WAL (SQLITE_BUSY_SNAPSHOT is not retried by the busy handler); use BEGIN IMMEDIATE for write transactions.
  3. A single large write transaction (for example a big eviction pass or a bulk page insert) holding the lock longer than 15 seconds under 10-way contention.

Acceptance Criteria

  • 10 concurrent squirrel audit runs of 10 different sites on one machine all complete and write their reports, repeated 5 times with no SQLite database is busy failure.
  • busy_timeout is the first pragma applied on every connection to content-store.db, the link cache and project.db.
  • Write transactions that can contend use BEGIN IMMEDIATE (or an equivalent retry), covered by a test with two processes writing at once.
  • If the lock still cannot be acquired within the timeout, the error says which database file was busy and how long it waited.

Activity

  1. added
    bug
    size: M
    on Oct 28, 2026
  2. added theissue type on Oct 28, 2026
  3. nc9 commented on Oct 30, 2026

    @nc9
    ContributorAuthor

    Shipped in v0.0.143 (commits 546e098, 14fee0e, b8018fb). Checked every acceptance criterion against current main: parallel audits no longer fail with SQLite busy. I also ran the literal repro on main: 10 concurrent squirrel audit runs of 10 different sites, repeated 5 times, 50 of 50 exited 0 with a report and no busy error.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions