From 2d276013ac43b976c1796578d9445b7823e3662e Mon Sep 17 00:00:00 2001 From: Calvin French-Owen Date: Thu, 27 Sep 2012 18:32:09 -0700 Subject: [PATCH 1/4] Adding a fix for timeouts, return reply not available when there is no further client in pool and clients --- lib/pool.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index 0d5f047..b4fc84d 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -69,7 +69,7 @@ util.inherits(Pool, process.EventEmitter); * @param {Function} callback The callback to invoke when all connections have been made */ Pool.prototype.connect = function(callback){ - var i = 0, finished = 0, self = this, + var i = 0, finished = 0, self = this, len = this.hosts.length * this.hostPoolSize, connected = 0; @@ -82,12 +82,12 @@ Pool.prototype.connect = function(callback){ connected += 1; self.clients.push(connection); } - + if(finished === len){ if(self.clients.length === 0){ - replyNotAvailable(callback); + return replyNotAvailable(callback); } - + //set the keyspaces connection to be the pool if(keyspace){ keyspace.connection = self; From 6b014f9297ef8c2ba98b63671e2e0274ae61c3b6 Mon Sep 17 00:00:00 2001 From: Calvin French-Owen Date: Thu, 27 Sep 2012 19:04:05 -0700 Subject: [PATCH 2/4] Updating pool to continue to monitorconnections --- lib/pool.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/pool.js b/lib/pool.js index b4fc84d..7b2d24a 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -84,17 +84,16 @@ Pool.prototype.connect = function(callback){ } if(finished === len){ - if(self.clients.length === 0){ - return replyNotAvailable(callback); - } - //set the keyspaces connection to be the pool if(keyspace){ keyspace.connection = self; } //we only want to callback once, after we get the final connection - callback(null, keyspace); - + if(self.clients.length === 0){ + replyNotAvailable(callback); + } else { + callback(null, keyspace); + } //now that we have a connection, lets start monitoring self.monitorConnections(); } From 8c709118c9553a477dd8c588db07b67bb9c35441 Mon Sep 17 00:00:00 2001 From: Calvin French-Owen Date: Thu, 27 Sep 2012 19:42:25 -0700 Subject: [PATCH 3/4] Adding emit for close if there is no clients open --- lib/pool.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/pool.js b/lib/pool.js index 7b2d24a..99ccb0c 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -316,12 +316,17 @@ Pool.prototype.close = function(){ clearInterval(this.retryInterval); + if (len === 0){ + this.emit('close'); + } + function closed(){ j += 1; if(j === len){ self.emit('close'); } } + for(; i < len; i += 1){ this.clients[i].on('close', closed); this.clients[i].close(); From dc6df1414b66a5cfc0e12550fbec26e94708ddc5 Mon Sep 17 00:00:00 2001 From: Calvin French-Owen Date: Thu, 27 Sep 2012 19:58:55 -0700 Subject: [PATCH 4/4] Updating tests to close the bad connection --- test/cql2.js | 1 + test/cql3.js | 1 + test/thrift.js | 1 + 3 files changed, 3 insertions(+) diff --git a/test/cql2.js b/test/cql2.js index d3badb5..315fc3f 100644 --- a/test/cql2.js +++ b/test/cql2.js @@ -33,6 +33,7 @@ module.exports = { assert.isDefined(err); badConn.cql(config['create_ks#cql'], function(err, res){ assert.isDefined(err); + badConn.close(); test.finish(); }); }); diff --git a/test/cql3.js b/test/cql3.js index 2f2bc63..60b35e2 100644 --- a/test/cql3.js +++ b/test/cql3.js @@ -60,6 +60,7 @@ module.exports = { assert.isDefined(err); badConn.cql(config['create_ks#cql'], function(err, res){ assert.isDefined(err); + badConn.close(); test.finish(); }); }); diff --git a/test/thrift.js b/test/thrift.js index 1c55dfe..eaea608 100644 --- a/test/thrift.js +++ b/test/thrift.js @@ -47,6 +47,7 @@ module.exports = { assert.isDefined(err); badConn.dropKeyspace(config.keyspace, function(err){ assert.isDefined(err); + badConn.close(); test.finish(); }); });