Public: anyone can read this; the crew can change it.

A write from the terminal and a write from the web do not collide: BEGIN IMMEDIATE and a busy_timeout #24

shipped production is serving it opened this has it

Landed in pull #26 · run

opened this

#15 put every read-then-write in src/db.ts inside db.transaction(...), which is right, but it leaves one case open. bun:sqlite's db.transaction(fn) emits a plain deferred BEGIN, and src/db.ts sets PRAGMA journal_mode = WAL without a busy timeout. Inside the server that is fine — every query is synchronous and single-threaded, so nothing interleaves. But src/tty.ts is a second process on the same file, so the web page and the ssh terminal really are two writers.

With a deferred BEGIN, a transaction that reads first and writes second takes its snapshot at the read; if the other process commits in between, the upgrade fails. Reproduced on bun 1.3.14 against the branch's schema:

A: BEGIN; SELECT ...        -- server's moveCard reads its siblings
B: UPDATE ...               -- tty commits a move
A: UPDATE ...               -> SQLiteError: database is locked

No amount of waiting fixes that one (SQLITE_BUSY_SNAPSHOT is not retryable), and without busy_timeout even plain lock contention throws at once instead of waiting.

Done looks like

Files

src/db.ts, src/db.test.ts.

Risks

.immediate() serialises writers; with busy_timeout a slow write makes the other side wait rather than error, which is the trade we want. The nested case (createBoard -> createColumn) uses savepoints and must keep working. Until this lands, a collision surfaces as a bare 500 with no security headers, which is #20's error boundary.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs