@malloydata/db-duckdb 0.0.388 → 0.0.389

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -64,10 +64,19 @@ export declare class DuckDBConnection extends DuckDBCommon {
64
64
  close(): Promise<void>;
65
65
  idle(): Promise<void>;
66
66
  /**
67
- * Remove this connection from the shared `activeDBs` entry. When the
68
- * last connection sharing the entry is removed, close the underlying
69
- * `DuckDBInstance` and drop the entry — releasing DuckDB's per-process
70
- * file lock.
67
+ * Dispose this connection's stake in the underlying `DuckDBInstance`:
68
+ * 1. Disconnect the per-connection C++ `Connection` so its
69
+ * `ClientContext` stops pinning the `DatabaseInstance`.
70
+ * 2. Drop our entry from the shared `activeDBs` bookkeeping.
71
+ * 3. If we were the last sharer, close the instance — which releases
72
+ * DuckDB's per-process file lock.
73
+ *
74
+ * Step 1 is required even though step 3 calls `instance.closeSync()`.
75
+ * The C-API `duckdb_close` only decrements the `shared_ptr<DatabaseInstance>`
76
+ * refcount; live `Connection` objects keep that refcount above zero via
77
+ * their `ClientContext`, so the file handle (and `fcntl` lock) survive
78
+ * the `closeSync` call. Disconnecting first guarantees the `closeSync`
79
+ * is the last ref and the lock is actually released.
71
80
  */
72
81
  private detachInstance;
73
82
  /**
@@ -295,12 +295,24 @@ class DuckDBConnection extends duckdb_common_1.DuckDBCommon {
295
295
  // re-acquire the lock immediately and defeat the point of idling.
296
296
  }
297
297
  /**
298
- * Remove this connection from the shared `activeDBs` entry. When the
299
- * last connection sharing the entry is removed, close the underlying
300
- * `DuckDBInstance` and drop the entry — releasing DuckDB's per-process
301
- * file lock.
298
+ * Dispose this connection's stake in the underlying `DuckDBInstance`:
299
+ * 1. Disconnect the per-connection C++ `Connection` so its
300
+ * `ClientContext` stops pinning the `DatabaseInstance`.
301
+ * 2. Drop our entry from the shared `activeDBs` bookkeeping.
302
+ * 3. If we were the last sharer, close the instance — which releases
303
+ * DuckDB's per-process file lock.
304
+ *
305
+ * Step 1 is required even though step 3 calls `instance.closeSync()`.
306
+ * The C-API `duckdb_close` only decrements the `shared_ptr<DatabaseInstance>`
307
+ * refcount; live `Connection` objects keep that refcount above zero via
308
+ * their `ClientContext`, so the file handle (and `fcntl` lock) survive
309
+ * the `closeSync` call. Disconnecting first guarantees the `closeSync`
310
+ * is the last ref and the lock is actually released.
302
311
  */
303
312
  detachInstance() {
313
+ if (this.connection) {
314
+ this.connection.disconnectSync();
315
+ }
304
316
  const activeDB = DuckDBConnection.activeDBs[this.shareKey];
305
317
  if (activeDB) {
306
318
  activeDB.connections = activeDB.connections.filter(connection => connection !== this.connection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/db-duckdb",
3
- "version": "0.0.388",
3
+ "version": "0.0.389",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -60,7 +60,7 @@
60
60
  "dependencies": {
61
61
  "@duckdb/duckdb-wasm": "1.33.1-dev13.0",
62
62
  "@duckdb/node-api": "1.4.4-r.1",
63
- "@malloydata/malloy": "0.0.388",
63
+ "@malloydata/malloy": "0.0.389",
64
64
  "@motherduck/wasm-client": "^0.6.6",
65
65
  "apache-arrow": "^17.0.0",
66
66
  "web-worker": "^1.3.0"