Comparing version 2.0.7 to 2.0.8
24
index.js
@@ -28,6 +28,2 @@ 'use strict' | ||
function throwOnRelease () { | ||
throw new Error('Release called on client which has already been released to the pool.') | ||
} | ||
function promisify (Promise, callback) { | ||
@@ -252,3 +248,3 @@ if (callback) { | ||
if (released) { | ||
throwOnRelease() | ||
throw new Error('Release called on client which has already been released to the pool.') | ||
} | ||
@@ -325,2 +321,3 @@ | ||
cb = response.callback | ||
this.connect((err, client) => { | ||
@@ -330,5 +327,22 @@ if (err) { | ||
} | ||
let clientReleased = false | ||
const onError = (err) => { | ||
if (clientReleased) { | ||
return | ||
} | ||
clientReleased = true | ||
client.release(err) | ||
cb(err) | ||
} | ||
client.once('error', onError) | ||
this.log('dispatching query') | ||
client.query(text, values, (err, res) => { | ||
this.log('query dispatched') | ||
client.removeListener('error', onError) | ||
if (clientReleased) { | ||
return | ||
} | ||
clientReleased = true | ||
client.release(err) | ||
@@ -335,0 +349,0 @@ if (err) { |
{ | ||
"name": "pg-pool", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"description": "Connection pool for node-postgres", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -35,3 +35,2 @@ # pg-pool | ||
max: 20, // set pool max size to 20 | ||
min: 4, // set min pool size to 4 | ||
idleTimeoutMillis: 1000, // close idle clients after 1 second | ||
@@ -38,0 +37,0 @@ connectionTimeoutMillis: 1000, // return an error after 1 second if connection could not be established |
@@ -229,2 +229,17 @@ 'use strict' | ||
}) | ||
it('handles post-checkout client failures in pool.query', (done) => { | ||
const pool = new Pool({ max: 1 }) | ||
pool.on('error', () => { | ||
// We double close the connection in this test, prevent exception caused by that | ||
}) | ||
pool.query('SELECT pg_sleep(5)', [], (err) => { | ||
expect(err).to.be.an(Error) | ||
done() | ||
}) | ||
setTimeout(() => { | ||
pool._clients[0].end() | ||
}, 1000) | ||
}) | ||
}) |
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
55007
1283
351