diff --git a/lib/pool.js b/lib/pool.js index bb7a918d..15cf77ed 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -80,11 +80,17 @@ var oldConnect = function(pool, client, cb) { var tid = setTimeout(function() { console.error(errorMessage); }, alarmDuration); + var onError = function() { + clearTimeout(tid); + client.removeListener('drain', release); + }; var release = function() { clearTimeout(tid); pool.release(client); + client.removeListener('error', onError); }; client.once('drain', release); + client.once('error', onError); cb(null, client); }; diff --git a/test/integration/connection-pool/error-tests.js b/test/integration/connection-pool/error-tests.js index b540979f..11badf04 100644 --- a/test/integration/connection-pool/error-tests.js +++ b/test/integration/connection-pool/error-tests.js @@ -17,7 +17,6 @@ helper.pg.connect(helper.config, assert.success(function(client) { assert.ok(error); assert.ok(brokenClient); assert.equal(client.id, brokenClient.id); - client.emit('drain'); helper.pg.end(); }); //kill the connection from client