Skip to content

fix(memory): wait for short concurrent SQLite writes - #188

Open
MoonCaves wants to merge 1 commit into
mnemon-dev:masterfrom
MoonCaves:fix/sqlite-busy-timeout
Open

MoonCaves wants to merge 1 commit into
mnemon-dev:masterfrom
MoonCaves:fix/sqlite-busy-timeout

Conversation

@MoonCaves

Copy link
Copy Markdown
Contributor

What

Writable memory connections now wait up to five seconds when SQLite is briefly locked by another writer. This lets a command continue after a short concurrent write instead of failing immediately with SQLITE_BUSY.

Why

Multiple agent processes can write to the same memory database concurrently. A foreground command that opens the writable store also runs migrations, and without a busy timeout that open can fail immediately while another short transaction is committing.

OpenLiveReadOnly already sets busy_timeout(250); the writable Open path had none. Five seconds is a starting value; happy to change it if you prefer another bound.

Verification

  • Added a regression test that checks the busy timeout on newly opened connections. It fails on current master (busy_timeout = 0) and passes with this change.
  • Reproduced the lock failure on the unmodified code (open database: migrate: backfill stored_at: database is locked (5) (SQLITE_BUSY) while a second connection held a write transaction) and verified that the same command succeeds with the timeout configured.
  • go vet ./... and go test ./... pass.

Checklist

  • New behavior is covered by a test.
  • Deterministic tests pass.
  • No user-facing documentation changes are needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant