From 9c5cd8d02db873877a96ba51a11b23ae8b310436 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Mon, 17 Mar 2014 18:51:32 +0100 Subject: [PATCH 1/2] Remove disconnected clients from the pool Might fix #458 Fixes https://github.com/CartoDB/CartoDB-SQL-API/issues/135 --- lib/pool.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/pool.js b/lib/pool.js index 9cf9aabf0..02e7ddbb5 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -33,6 +33,11 @@ var pools = { pool.destroy(client); }); + // Remove connection from pool on disconnect + client.on('end', function(e) { + pool.destroy(client); + }); + return cb(null, client); }); }, From fb118cf069ede16bfe0f2e29556538a6ed8b6b38 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 18 Mar 2014 09:42:19 +0100 Subject: [PATCH 2/2] Avoid loop between pool.destroy and client.end --- lib/pool.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pool.js b/lib/pool.js index 02e7ddbb5..887a0e4ed 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -35,13 +35,18 @@ var pools = { // Remove connection from pool on disconnect client.on('end', function(e) { - pool.destroy(client); + // 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(); } });