Documentation

Docs / Reference

ADR 0043 - SQLite read busy timeout

Status: Accepted (delegated review, 2026-11-03)

Context

graphvein serve reads the index through sqlite.OpenRead, which set no busy timeout. A status or API section request that met a write lock held by a concurrent graphvein index failed at once with SQLITE_BUSY: 500 store_error, or freshness unknown. ADR 0041 records this as a known gap of re-indexing while serve runs. graphvein status, query, callers and impact share OpenRead and failed the same way.

Verified semantics (2026-11-03, task T016g). The driver is modernc.org/sqlite v1.60.1 (pure Go, SQLite 3.53.4), not the ADR 0002 cgo package. www.sqlite.org could not be fetched (proxy 403); the facts come from the driver's source and from experiments against it in scratch:

  1. The store uses rollback journaling (journal_mode is delete); nothing sets WAL. Readers block on writers.
  2. An open write transaction holds RESERVED, which readers pass, until it modifies the database file; from then until it ends it holds EXCLUSIVE, which blocks every reader. The file is modified at commit, or earlier when the page cache spills. ingest keeps one transaction from BeginRun to Commit.
  3. Self-index of this repository on Linux: an unchanged re-index showed no BUSY; a full rewrite (about 45 MB of new rows) showed short BUSY bursts (10-345 ms) on cache spills and one 5.0 s block at commit.
  4. database/sql may close and reopen pooled connections. A PRAGMA busy_timeout sent with ExecContext configures only the connection that ran it (after a recycle it read 0). The driver applies DSN parameters (_pragma=busy_timeout(N), _busy_timeout=N) to every new connection; with a file: URI SQLite keeps mode=ro.
  5. The busy wait ignores the request context: the driver's cancellation calls sqlite3_interrupt, which does not stop the busy handler's sleep, and the driver exposes no busy-handler hook.
  6. Postgres readers do not block on an uncommitted run (MVCC).

Options considered

Decision

sqlite.OpenRead opens file:<abs path>?mode=ro&_pragma=busy_timeout(3000), so every pooled read connection waits up to 3 s for a lock (readBusyTimeout; openRead and readDSN take the bound so tests can use a short one).

Why 3 s: it covers incremental re-index commit windows (fact 3); it stays below serve's 5 s shutdown grace, because the wait cannot be cancelled (fact 5); it is far below the web client's 15 s request timeout and the server's 2 min WriteTimeout.

When the bound is exceeded nothing new is reported: status answers 500 store_error (runs read) or freshness unknown, an API section 500 store_error, exactly as before. Never fresh, never an empty or partial answer, no new error code. There is no single snapshot per request: a read that waited returns the newly committed state, and the API section's runs-before/after check sees the new run, repeats once, then answers 503 index_changed (ADR 0042 section 6).

graphvein status, query, callers and impact share OpenRead, so they also wait up to 3 s instead of failing at once. This is intended.

This narrows the re-index known gap of ADR 0041: a request overlapping a commit shorter than 3 s now waits and answers correctly.

Consequences

Known gaps

Review notes (delegated review, 2026-11-03)

Report a problem with this pageSource: docs/adr/0043-sqlite-read-busy-timeout.md