From 1c171773697f95d69a3c60e47335f102ef469401 Mon Sep 17 00:00:00 2001 From: Jos Kuijpers Date: Wed, 30 Jul 2014 14:17:04 +0200 Subject: [PATCH] Only call destroy on a client when it is not already being destroyed Adds a check in the error listener on the client in the pool, to prevent calling destroy on a client when it is already being destroyed. Without this check, if an error occurs during the ending of the stream, such as a timeout, the client is never removed from the pool and weird things happen. --- lib/pool.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index 7ff0b0f8..b85a6738 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