node-firebird 2.15.0 → 2.15.1

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.
Files changed (3) hide show
  1. package/lib/pool.js +16 -5
  2. package/package.json +2 -2
  3. package/src/pool.ts +15 -5
package/lib/pool.js CHANGED
@@ -258,6 +258,12 @@ class Pool extends events_1.default.EventEmitter {
258
258
  self.internaldb.splice(self.internaldb.indexOf(db), 1);
259
259
  self.emit('remove', db);
260
260
  }
261
+ else if (self._destroyed) {
262
+ // destroy() deliberately does not wait for checked-out
263
+ // connections. Close one for good when its caller later
264
+ // releases it instead of returning it to a stopped pool.
265
+ self._retire(db);
266
+ }
261
267
  else if (self._isExpired(db)) {
262
268
  // worn out (maxUses / maxLifetimeMillis): close it
263
269
  // for good instead of returning it to the idle
@@ -318,7 +324,7 @@ class Pool extends events_1.default.EventEmitter {
318
324
  callback();
319
325
  }
320
326
  }
321
- this.internaldb.forEach(function (db) {
327
+ this.internaldb.slice().forEach(function (db) {
322
328
  if (db.connection._pooled === false) {
323
329
  detachCallback();
324
330
  return;
@@ -326,15 +332,20 @@ class Pool extends events_1.default.EventEmitter {
326
332
  // check if the db is not free into the pool otherwise user should manual detach it
327
333
  var _db_in_pool = self.pooldb.indexOf(db);
328
334
  if (_db_in_pool !== -1) {
329
- self.pooldb.splice(_db_in_pool, 1);
330
335
  db.connection._pooled = false;
331
- db.detach(detachCallback);
332
- self.emit('remove', db);
336
+ // Keep the connection marked idle until physical detach emits
337
+ // its detach event. The listener above will then ignore that
338
+ // event instead of counting it as an active release.
339
+ db.detach(function (err) {
340
+ self._forget(db);
341
+ detachCallback(err);
342
+ });
333
343
  }
334
344
  else {
335
345
  // [Fix 5] Connection is currently in use (dbinuse > 0).
336
346
  // The caller is responsible for releasing it via detach().
337
- // Count it down here so the destroy() callback is not blocked forever.
347
+ // Count it down here so the destroy() callback is not blocked forever;
348
+ // the detach listener retires it when the caller releases it.
338
349
  detachCallback();
339
350
  }
340
351
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-firebird",
3
- "version": "2.15.0",
3
+ "version": "2.15.1",
4
4
  "description": "Pure JavaScript and Asynchronous Firebird client for Node.js.",
5
5
  "keywords": [
6
6
  "firebird",
@@ -58,6 +58,6 @@
58
58
  "@types/node": "^26.1.1",
59
59
  "oxlint": "^0.15.11",
60
60
  "typescript": "^7.0.2",
61
- "vitest": "^4.0.18"
61
+ "vitest": "^4.1.11"
62
62
  }
63
63
  }
package/src/pool.ts CHANGED
@@ -281,6 +281,11 @@ class Pool extends Events.EventEmitter {
281
281
  if (db.connection._isClosed || db.connection._isDetach || db.connection._pooled === false) {
282
282
  self.internaldb.splice(self.internaldb.indexOf(db), 1);
283
283
  self.emit('remove', db);
284
+ } else if (self._destroyed) {
285
+ // destroy() deliberately does not wait for checked-out
286
+ // connections. Close one for good when its caller later
287
+ // releases it instead of returning it to a stopped pool.
288
+ self._retire(db);
284
289
  } else if (self._isExpired(db)) {
285
290
  // worn out (maxUses / maxLifetimeMillis): close it
286
291
  // for good instead of returning it to the idle
@@ -348,7 +353,7 @@ class Pool extends Events.EventEmitter {
348
353
  }
349
354
  }
350
355
 
351
- this.internaldb.forEach(function(db) {
356
+ this.internaldb.slice().forEach(function(db) {
352
357
  if (db.connection._pooled === false) {
353
358
  detachCallback();
354
359
  return;
@@ -356,14 +361,19 @@ class Pool extends Events.EventEmitter {
356
361
  // check if the db is not free into the pool otherwise user should manual detach it
357
362
  var _db_in_pool = self.pooldb.indexOf(db);
358
363
  if (_db_in_pool !== -1) {
359
- self.pooldb.splice(_db_in_pool, 1);
360
364
  db.connection._pooled = false;
361
- db.detach(detachCallback);
362
- self.emit('remove', db);
365
+ // Keep the connection marked idle until physical detach emits
366
+ // its detach event. The listener above will then ignore that
367
+ // event instead of counting it as an active release.
368
+ db.detach(function(err?: any) {
369
+ self._forget(db);
370
+ detachCallback(err);
371
+ });
363
372
  } else {
364
373
  // [Fix 5] Connection is currently in use (dbinuse > 0).
365
374
  // The caller is responsible for releasing it via detach().
366
- // Count it down here so the destroy() callback is not blocked forever.
375
+ // Count it down here so the destroy() callback is not blocked forever;
376
+ // the detach listener retires it when the caller releases it.
367
377
  detachCallback();
368
378
  }
369
379
  });