Permalink
Browse files

Merge pull request #76 from calvinfo/master

Fixing double callback/timeout not closed problem
  • Loading branch information...
devdazed committed Sep 28, 2012
2 parents bcf5c7e + dc6df14 commit 791da9543ab02218176001ccba70bb932385f825
Showing with 15 additions and 8 deletions.
  1. +12 −8 lib/pool.js
  2. +1 −0 test/cql2.js
  3. +1 −0 test/cql3.js
  4. +1 −0 test/thrift.js
View
@@ -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,19 +82,18 @@ Pool.prototype.connect = function(callback){
connected += 1;
self.clients.push(connection);
}
-
+
if(finished === len){
- if(self.clients.length === 0){
- 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();
}
@@ -317,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();
View
@@ -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();
});
});
View
@@ -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();
});
});
View
@@ -47,6 +47,7 @@ module.exports = {
assert.isDefined(err);
badConn.dropKeyspace(config.keyspace, function(err){
assert.isDefined(err);
+ badConn.close();
test.finish();
});
});

0 comments on commit 791da95

Please sign in to comment.