Skip to content

Drizzle SQLite across processes: busy wait and busy-commit rerun #142

Open

Description

@duarteplesteves

Parent

#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.
  • Conformance and the negative control from Drizzle SQLite Adapter: tables, the in-process lock, full Conformance #141 stay green.
  • A changeset is added.

Activity

  1. duarteplesteves commented on Nov 19, 2026

    @duarteplesteves
    OwnerAuthor

    Blocked upstream on libsql.

    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:

    const held = await holder.transaction("write");
    await client.transaction("write").catch((e) => e.code);   // SQLITE_BUSY, expected
    await held.commit();
    const tx = await client.transaction("write");
    await tx.execute("INSERT INTO t VALUES (1)");
    await tx.commit();  // SQLITE_BUSY: ... SQL statements in progress, every attempt
    // with --expose-gc and a few gc() + ticks before the retry: COMMIT ok

    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.43 still fails on the BEGIN IMMEDIATE path.

    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.

  2. duarteplesteves commented on Nov 19, 2026

    @duarteplesteves
    OwnerAuthor

    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.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions