Comparing version 3.4.1 to 3.5.1
32
index.js
@@ -87,2 +87,3 @@ 'use strict' | ||
this.options.allowExitOnIdle = this.options.allowExitOnIdle || false | ||
this.options.maxLifetimeSeconds = this.options.maxLifetimeSeconds || 0 | ||
this.log = this.options.log || function () {} | ||
@@ -98,2 +99,3 @@ this.Client = this.options.Client || Client || require('pg').Client | ||
this._idle = [] | ||
this._expired = new WeakSet() | ||
this._pendingQueue = [] | ||
@@ -128,2 +130,3 @@ this._endCallback = undefined | ||
} | ||
// if we don't have any waiting, do nothing | ||
@@ -254,2 +257,18 @@ if (!this._pendingQueue.length) { | ||
if (this.options.maxLifetimeSeconds !== 0) { | ||
setTimeout(() => { | ||
this.log('ending client due to expired lifetime') | ||
this._expired.add(client) | ||
const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client) | ||
if (idleIndex !== -1) { | ||
this._acquireClient( | ||
client, | ||
new PendingItem((err, client, clientRelease) => clientRelease()), | ||
idleListener, | ||
false | ||
) | ||
} | ||
}, this.options.maxLifetimeSeconds * 1000) | ||
} | ||
return this._acquireClient(client, pendingItem, idleListener, true) | ||
@@ -325,2 +344,11 @@ } | ||
const isExpired = this._expired.has(client) | ||
if (isExpired) { | ||
this.log('remove expired client') | ||
this._expired.delete(client) | ||
this._remove(client) | ||
this._pulseQueue() | ||
return | ||
} | ||
// idle timeout | ||
@@ -422,2 +450,6 @@ let tid | ||
get expiredCount() { | ||
return this._clients.reduce((acc, client) => acc + (this._expired.has(client) ? 1 : 0), 0) | ||
} | ||
get totalCount() { | ||
@@ -424,0 +456,0 @@ return this._clients.length |
{ | ||
"name": "pg-pool", | ||
"version": "3.4.1", | ||
"version": "3.5.1", | ||
"description": "Connection pool for node-postgres", | ||
@@ -40,3 +40,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "92b4d37926c276d343bfe56447ff6f526af757cf" | ||
"gitHead": "4fa7ee891a456168a75695ac026792136f16577f" | ||
} |
@@ -139,3 +139,3 @@ # pg-pool | ||
var name = await pool.query('select $1::text as name', ['brianc']) | ||
console.log(name.rows[0].name, 'says hello at', time.rows[0].name) | ||
console.log(name.rows[0].name, 'says hello at', time.rows[0].now) | ||
``` | ||
@@ -142,0 +142,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67807
22
1603