Skip to content
Browse files

Adding fix for connections when last node might be down

  • Loading branch information...
1 parent f505b90 commit 6a3a4351fec7214c2aea9303f809ab98598141d0 @calvinfo committed
Showing with 4 additions and 7 deletions.
  1. +4 −7 lib/pool.js
View
11 lib/pool.js
@@ -71,7 +71,7 @@ util.inherits(Pool, process.EventEmitter);
Pool.prototype.connect = function(callback){
var i = 0, finished = 0, self = this,
len = this.hosts.length * this.hostPoolSize,
- connected = 0;
+ connected = 0, poolKeyspace;
function onConnect(err, connection, keyspace, host){
finished += 1;
@@ -80,22 +80,19 @@ Pool.prototype.connect = function(callback){
self.dead.push(host);
} else {
connected += 1;
-
if(keyspace){
+ poolKeyspace = keyspace;
keyspace.connection = self;
}
self.clients.push(connection);
-
- // Callback on the first good client.
- if(connected === 1){
- callback(null, keyspace);
- }
}
if(finished === len){
// if there are no clients, we haven't called back and are not available
if(connected === 0){
replyNotAvailable(callback);
+ } else {
+ callback(null, poolKeyspace);
}
//now that we have a connection, lets start monitoring
self.monitorConnections();

0 comments on commit 6a3a435

Please sign in to comment.
Something went wrong with that request. Please try again.