From e5a63ab58d7fc920d8eb74674518788acb5e18b2 Mon Sep 17 00:00:00 2001 From: Oliver Salzburg Date: Mon, 24 Aug 2015 16:18:43 +0200 Subject: [PATCH] Don't emit error events parsed out of data stream --- lib/pool.js | 5 +++++ test/unit/pool/basic-tests.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index b85a673..00cce7c 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -23,9 +23,14 @@ var pools = { log: clientConfig.poolLog || defaults.poolLog, create: function(cb) { var client = new pools.Client(clientConfig); + // Ignore errors on pooled clients until they are connected. + client.on('error', Function.prototype); client.connect(function(err) { if(err) return cb(err, null); + // Remove the noop error handler after a connection has been established. + client.removeListener('error', Function.prototype); + //handle connected client background errors by emitting event //via the pg object and then removing errored client from the pool client.on('error', function(e) { diff --git a/test/unit/pool/basic-tests.js b/test/unit/pool/basic-tests.js index 1e54672..2bf458a 100644 --- a/test/unit/pool/basic-tests.js +++ b/test/unit/pool/basic-tests.js @@ -121,9 +121,10 @@ test('pool with connection error on connection', function() { process.nextTick(function() { cb(new Error('Could not connect')); }); - } + }, + on: Function.prototype }; - } + }; test('two parameters', function() { var p = pools.getOrCreate(poolId++); p.connect(assert.calls(function(err, client) {