Skip to content

Commit f28c6c0

Browse files
irparentclaude
andcommitted
A second close of a connection does nothing; the driver tests follow where native is refused
- The seam's connection count called the driver's close() before checking whether that connection was already closed. node:sqlite throws on a second close ("database is not open"); better-sqlite3 does not. The file is still let go only after a close that succeeded. A driver test now closes a built-in connection twice on every cell that has the built-in driver. - The job that builds the addon from source refuses native on Node 24 (nodejs/node#65446). There the worker test asserts that refusal and runs the drivers that open, and the connection-count test skips reopening the file with a copy that cannot load. - The two-copies CI step splits each pair explicitly and quotes both halves (shellcheck SC2086). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 8d0b1e4 commit f28c6c0

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ jobs:
325325
run: |
326326
bad=0
327327
for pair in "native native" "node node" "native node" "node native"; do
328-
set -- $pair
328+
set -- "${pair% *}" "${pair#* }"
329329
died=0
330330
for i in $(seq 1 10); do
331331
node tests/fixtures/worker-exit/two-sqlites.cjs "$1" "$2" 100 > out.txt 2> err.txt || { died=$((died + 1)); echo " main=$1 worker=$2 run $i: exit $? $(grep -v -E 'ExperimentalWarning|trace-warnings' err.txt | head -1)"; }

‎src/storage/driver.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,10 @@ function held(key: string, driver: Driver): Driver {
538538
let open = true;
539539
return {
540540
...driver,
541+
// A second close of one connection does nothing: node:sqlite throws on it where better-sqlite3 does not. The file is let go only after a close that succeeded.
541542
close: () => {
542-
driver.close();
543543
if (!open) return;
544+
driver.close();
544545
open = false;
545546
const now = holders.get(key);
546547
if (now && --now.count === 0) holders.delete(key);

‎tests/unit/storage/driver.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,15 +491,25 @@ describe('one copy of SQLite per file', () => {
491491
if (process.platform === 'win32' || process.platform === 'darwin') expect(sqliteHolding(path.toUpperCase())).toBe(a.name);
492492
b.close();
493493
expect(sqliteHolding(path)).toBeUndefined();
494-
if (!builtIn) return;
494+
// A second close does nothing on either copy: node:sqlite throws on it where better-sqlite3 does not.
495+
if (builtIn) {
496+
const n = openDriver(tempDb(), { driver: 'node' });
497+
n.close();
498+
expect(() => n.close()).not.toThrow();
499+
}
500+
// Let go, the file opens with the other copy: when both can open here (the job that builds the addon from source refuses native on Node 24).
501+
if (!builtIn || (other(a) === 'native' && nativeAbortsOnCollect(nativeBinaryPath()))) return;
495502
const c = openDriver(path, { driver: other(a) });
496503
drivers.push(c);
497504
expect(c.name).not.toBe(a.name);
498505
expect(sqliteHolding(':memory:')).toBeUndefined();
499506
});
500507

501508
it("the search worker and the checkpoint worker are handed the copy the store's connection got, on either driver", async () => {
502-
for (const driver of builtIn ? (['native', 'node'] as const) : (['native'] as const)) {
509+
// Each driver that opens here. Where native is refused (the job that builds the addon from source), the refusal is the check for it.
510+
const nativeRefused = nativeAbortsOnCollect(nativeBinaryPath());
511+
if (nativeRefused) expect(() => new SqliteAdapter(tempDb(), { driver: 'native' })).toThrow(/nodejs\/node#65446/);
512+
for (const driver of [...(nativeRefused ? [] : (['native'] as const)), ...(builtIn ? (['node'] as const) : [])]) {
503513
const storage = new SqliteAdapter(tempDb(), { driver });
504514
await storage.initialize();
505515
try {

0 commit comments

Comments
 (0)