You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Drizzle SQLite across processes: busy wait and busy-commit rerun #142
#138. Types and call stacks: tech spec (the immediate() pseudocode and Option 2 ②/③; Invariants I-no-rerun-on-wait and I-transient; the Failure Flow table; test plan slices 5 and 6).
What to build
Two processes writing to the same SQLite file can't double-book, and waiting for the other process never freezes Node.
Busy at the start. When another process holds the writer slot, BEGIN IMMEDIATE fails instantly (libsql's busy timeout is 0). The Adapter waits asynchronously with a capped back-off (5 → 100 ms) and tries BEGIN again, with no limit, like Postgres's advisory-lock wait. work is never entered while waiting, so it runs once.
Busy at commit.SQLITE_BUSY at COMMIT, after work ran, is transient: the whole unit reruns, also included, up to 3 attempts in total (ADR 008's rule, via the shared retryTransient). After that it rejects with the busy error as cause.
Acceptance criteria
Cross-process test: a second libsql client on the same file holds a write transaction. The Adapter's unit stays pending while a setInterval counter keeps ticking; after the holder commits, the unit completes and work was entered exactly once.
Commit-busy test (rollback-journal file, a reader client holding a read transaction across the unit's COMMIT): the unit reruns and succeeds once the reader closes (work ran twice).
If the reader never closes, the unit rejects after 3 attempts with cause.code === "SQLITE_BUSY".
A non-busy error after work is entered is not retried.
On libsql 0.5.29 (latest stable, via @libsql/client 0.18), a statement that fails with SQLITE_BUSY is never reset. It stays "in progress" on its pooled connection, so every later COMMIT on that connection fails with SQLITE_BUSY: cannot commit transaction - SQL statements in progress. The pool hands the same connection back on each retry, so both the busy-wait and the commit rerun fail. Only GC finalizing the statement recovers it.
Minimal repro, @libsql/client only:
constheld=awaitholder.transaction("write");awaitclient.transaction("write").catch((e)=>e.code);// SQLITE_BUSY, expectedawaitheld.commit();consttx=awaitclient.transaction("write");awaittx.execute("INSERT INTO t VALUES (1)");awaittx.commit();// SQLITE_BUSY: ... SQL statements in progress, every attempt// with --expose-gc and a few gc() + ticks before the retry: COMMIT ok
Plan: park until a libsql release fixes all three paths (busy BEGIN, busy write, busy COMMIT), then require that version. WIP lives on feat/142-sqlite-cross-process (b76f9e6: immediate() loop, commit-busy rerun, cross-process test; needs lint fixes, the commit-busy test, conformance and review). Interim guidance, one writer process per SQLite file: #153.
Moved out of 0.5.0: it ships with one writer process per SQLite file (#153). Tracked as a follow-up in the ROADMAP; picks up once libsql fixes the busy-statement reset.
Activity
duarteplesteves commentedon Nov 19, 2026
Blocked upstream on libsql.
On
libsql0.5.29 (latest stable, via@libsql/client0.18), a statement that fails withSQLITE_BUSYis never reset. It stays "in progress" on its pooled connection, so every laterCOMMITon that connection fails withSQLITE_BUSY: cannot commit transaction - SQL statements in progress. The pool hands the same connection back on each retry, so both the busy-wait and the commit rerun fail. Only GC finalizing the statement recovers it.Minimal repro,
@libsql/clientonly:Upstream: tursodatabase/libsql-js#240, tursodatabase/libsql-js#245, tursodatabase/libsql-client-ts#352. Proposed fix: tursodatabase/libsql-js#238. One report there says
0.6.0-pre.43still fails on theBEGIN IMMEDIATEpath.Plan: park until a libsql release fixes all three paths (busy
BEGIN, busy write, busyCOMMIT), then require that version. WIP lives onfeat/142-sqlite-cross-process(b76f9e6:immediate()loop, commit-busy rerun, cross-process test; needs lint fixes, the commit-busy test, conformance and review). Interim guidance, one writer process per SQLite file: #153.docs(sqlite): write to the SQLite file from one process only (#153)
docs(sqlite): write to the SQLite file from one process only (#153)
duarteplesteves commentedon Nov 19, 2026
Moved out of 0.5.0: it ships with one writer process per SQLite file (#153). Tracked as a follow-up in the ROADMAP; picks up once libsql fixes the busy-statement reset.