diff --git a/lib/pool.js b/lib/pool.js index 7ff0b0f..b85a673 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -30,7 +30,13 @@ var pools = { //via the pg object and then removing errored client from the pool client.on('error', function(e) { pool.emit('error', e, client); - pool.destroy(client); + + // If the client is already being destroyed, the error + // occurred during stream ending. Do not attempt to destroy + // the client again. + if (!client._destroying) { + pool.destroy(client); + } }); // Remove connection from pool on disconnect