Skip to content

urlcode-store operator commands may starve on the write lock beside a busy server (unverified) #1072

Closed

Description

@jimhoyd

Runtime revision and environment

main, with #1071 open at the time of filing. This is analysis only: nothing has been reproduced for the store.

Minimal reproduction

#1071 found that urlcode-auth create-user failed with database is locked on Windows CI while a serving process was committing continuously.

  • Cause. SQLite's busy handler (a 2 s busy_timeout) sleeps up to 100 ms between attempts and does not queue waiters. If each server commit holds the write lock for most of its time (a slow flush), all ~30 attempts can find the lock held.
  • Fix in fix(auth): operator commands poll for the write lock beside a busy server #1071. Auth's operator connection now polls BEGIN IMMEDIATE every millisecond for up to 10 s.

packages/store/src/database.ts opens connections with PRAGMA busy_timeout=${BUSY_TIMEOUT_MS} (2000 ms). If the urlcode-store operator commands (members, reassign, audit, ...) set up their connection the same way, they would starve the same way beside a saturated server.

Unverified. I have not checked the store's operator code paths or reproduced the problem. packages/auth/test/slow-commit-writer.ts from #1071 is a writer that holds the lock 25 ms per commit and could be used to reproduce it.

Relevant output

Auth repro before #1071: beside a writer that holds the lock 20 ms per commit, 4 of 5 create-user calls failed after about 2.4 s with database is locked.

Activity

  1. jimhoyd commented on Oct 1, 2026

    @jimhoyd
    CollaboratorAuthor

    The contention regression itself failed in the Node 24/macOS sweep at 9e8996bf: https://github.com/jimhoyd-com/urlcode/actions/runs/36805955980/job/110190237949 . Every operator call and the CLI command succeeded; the final commits > elapsed / 100 assertion failed with 135 commits in 16603 ms. This is an implicit minimum writer throughput of 10 commits/second, which the contract does not promise on shared runners.

    The fix replaces that rate assertion with read-only observation of the writer's committed rows, requiring fresh progress across each of the 15 operator rounds and the CLI call, with a bounded wait for a writer turn. The continuous 25 ms lock hold / 1 ms idle writer, all command success assertions, and final membership assertions remain. No production locking code or timeout changes are proposed. Validation is in progress.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions