Skip to content
This repository has been archived by the owner on Feb 22, 2019. It is now read-only.

Commit

Permalink
Merge pull request #78 from calvinfo/connect-fix
Browse files Browse the repository at this point in the history
Connect fix
  • Loading branch information
devdazed committed Oct 2, 2012
2 parents 791da95 + 7a24550 commit 16f7aa1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions lib/pool.js
Expand Up @@ -80,19 +80,22 @@ Pool.prototype.connect = function(callback){
self.dead.push(host); self.dead.push(host);
} else { } else {
connected += 1; connected += 1;
if(keyspace){
keyspace.connection = self;
}
self.clients.push(connection); self.clients.push(connection);
if (connected === 1) {
callback(null, keyspace);
}
if (self.closing) {
connection.close();
}
} }


if(finished === len){ if(finished === len){
//set the keyspaces connection to be the pool // if there are no clients, we haven't called back and are not available
if(keyspace){ if(connected === 0){
keyspace.connection = self;
}
//we only want to callback once, after we get the final connection
if(self.clients.length === 0){
replyNotAvailable(callback); replyNotAvailable(callback);
} else {
callback(null, keyspace);
} }
//now that we have a connection, lets start monitoring //now that we have a connection, lets start monitoring
self.monitorConnections(); self.monitorConnections();
Expand Down Expand Up @@ -296,6 +299,9 @@ Pool.prototype.monitorConnections = function(){
* Recursively pop through the dead hosts and try to reconnect * Recursively pop through the dead hosts and try to reconnect
*/ */
function checkDead(){ function checkDead(){

if(self.closing) return;

if(self.dead.length > 0){ if(self.dead.length > 0){
connect(self.dead.pop()); connect(self.dead.pop());
checkDead(); checkDead();
Expand Down
2 changes: 1 addition & 1 deletion test/thriftHostPool.js
@@ -1,5 +1,5 @@
/** /**
* Runs tests defined in thrift.js, but with ConnectionPool * Runs tests defined in thrift.js, but with ConnectionPool
* option hostPoolSize set to 5. * option hostPoolSize set to 5.
*/ */
var config = require('./helpers/thrift'), var config = require('./helpers/thrift'),
Expand Down

0 comments on commit 16f7aa1

Please sign in to comment.