@devries-cameron20 / t3code-1 / commits / 67ff912ccd
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): opening a database waits for another process's lock (#28288)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

yaacovcorcos committed Nov 1, 2026 at 23:50 UTC 67ff912ccdb1c0342f42f8797355f9664a549331
2 files changed +32
packages/shared/src/nodeSqliteClient.test.ts
+30
@@ -9,6 +9,8 @@ import * as FileSystem from "effect/FileSystem";
9 import * as Path from "effect/Path";
10 import * as SqlClient from "effect/sql/SqlClient";
11 import * as Statement from "effect/sql/Statement";
12 +import { ChildProcess, ChildProcessSpawner } from "effect/process";
13 +import * as Stream from "effect/Stream";
14 import type * as Tracer from "effect/Tracer";
15 import { vi } from "vite-plus/test";
16
@@ -192,6 +194,34 @@ it.effect("keeps another connection from committing between a transaction's read
194 }).pipe(Effect.provide(NodeServices.layer)),
195 );
196
197 +it.effect("waits for another process's lock while the database opens", () =>
198 + Effect.gen(function* () {
199 + const fs = yield* FileSystem.FileSystem;
200 + const path = yield* Path.Path;
201 + const directory = yield* fs.makeTempDirectoryScoped({ prefix: "t3-sqlite-open-" });
202 + const filename = path.join(directory, "state.sqlite");
203 + const seed = new NodeSqlite.DatabaseSync(filename);
204 + seed.exec("PRAGMA journal_mode = WAL; CREATE TABLE entries(name TEXT NOT NULL)");
205 + seed.close();
206 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
207 + const holder = yield* spawner.spawn(
208 + ChildProcess.make(process.execPath, [
209 + "-e",
210 + `const db = new (require("node:sqlite").DatabaseSync)(process.argv[1]);
211 + db.exec("PRAGMA locking_mode = EXCLUSIVE; BEGIN EXCLUSIVE");
212 + console.log("held");
213 + setTimeout(() => db.close(), 300);`,
214 + filename,
215 + ]),
216 + );
217 + yield* Stream.runHead(holder.stdout);
218 + yield* Effect.gen(function* () {
219 + const sql = yield* SqlClient.SqlClient;
220 + assert.deepEqual(yield* sql`SELECT COUNT(*) FROM entries`.values, [[0]]);
221 + }).pipe(Effect.provide(SqliteClient.layer({ filename, checkpointWorker: true })));
222 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
223 +);
224 +
225 it.effect("reports a transaction blocked by another writer as a lock timeout", () =>
226 Effect.gen(function* () {
227 const { filename, other } = yield* makeTempDatabase;
packages/shared/src/nodeSqliteClient.ts
+2
@@ -629,6 +629,8 @@ const startCheckpointWorker = Effect.fnUntraced(function* (
629 yield* warn("Node SQLite lacks transaction-state or statement-authorizer support");
630 return undefined;
631 }
632 + // These are the writer's first statements, before callers set their own wait.
633 + writer.exec("PRAGMA busy_timeout = 5000;");
634 const version = String(writer.prepare("SELECT sqlite_version() AS version").get()?.version);
635 const [major = 0, minor = 0] = version.split(".").map(Number);
636 // Older SQLite treats NOOP as PASSIVE, which would checkpoint on the writer.