diff --git a/lib/pool.js b/lib/pool.js index 9cf9aabf0..887a0e4ed 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -33,10 +33,20 @@ var pools = { pool.destroy(client); }); + // Remove connection from pool on disconnect + client.on('end', function(e) { + // Do not enter infinite loop between pool.destroy + // and client 'end' event... + if ( ! client._destroying ) { + pool.destroy(client); + } + }); + return cb(null, client); }); }, destroy: function(client) { + client._destroying = true; client.end(); } });