Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Connect fix #78

Merged
merged 3 commits into from Oct 2, 2012
View
@@ -80,19 +80,22 @@ Pool.prototype.connect = function(callback){
self.dead.push(host);
} else {
connected += 1;
+ if(keyspace){
+ keyspace.connection = self;
+ }
self.clients.push(connection);
+ if (connected === 1) {
+ callback(null, keyspace);
+ }
+ if (self.closing) {
+ connection.close();
+ }
}
if(finished === len){
- //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
- if(self.clients.length === 0){
+ // if there are no clients, we haven't called back and are not available
+ if(connected === 0){
replyNotAvailable(callback);
- } else {
- callback(null, keyspace);
}
//now that we have a connection, lets start monitoring
self.monitorConnections();
@@ -296,6 +299,9 @@ Pool.prototype.monitorConnections = function(){
* Recursively pop through the dead hosts and try to reconnect
*/
function checkDead(){
+
+ if(self.closing) return;
+
if(self.dead.length > 0){
connect(self.dead.pop());
checkDead();
View
@@ -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.
*/
var config = require('./helpers/thrift'),