From fb491cf569d42d029ed6eafa5bd48e8e15342115 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 14 Mar 2014 16:40:25 +0100 Subject: [PATCH 1/2] Remove client from pool on connection end Might fix #458 Definitely 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..dec450ef7 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -33,6 +33,11 @@ var pools = { pool.destroy(client); }); + // Remove client from pool on connection end + client.on('end', function() { + pool.destroy(client); + }); + return cb(null, client); }); }, From a3a1cc999c2f4db557c9c30654ffb8d3312eb4f7 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Fri, 14 Mar 2014 18:16:26 +0100 Subject: [PATCH 2/2] Not all "end" events have to be considered bogus connections Instead, consider receiving a premature stream end while a query is in progress as an error sign, bubbling up the error to the client level. Fixes the testsuite while still fixing my cases and possibly #458. The correct fix would be to provide a .validate method to the pooler, and expose a .validate method to the client and to the connection classes for that purpose... --- lib/client.js | 1 + lib/pool.js | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index 490e1d183..da8686d18 100644 --- a/lib/client.js +++ b/lib/client.js @@ -177,6 +177,7 @@ Client.prototype.connect = function(callback) { var disconnectError = new Error('Stream unexpectedly ended during query execution'); self.activeQuery.handleError(disconnectError); self.activeQuery = null; + self.emit('error', disconnectError); } self.emit('end'); }); diff --git a/lib/pool.js b/lib/pool.js index dec450ef7..9cf9aabf0 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -33,11 +33,6 @@ var pools = { pool.destroy(client); }); - // Remove client from pool on connection end - client.on('end', function() { - pool.destroy(client); - }); - return cb(null, client); }); },