Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #78 from calvinfo/connect-fix

Connect fix
  • Loading branch information...
commit 16f7aa1794723c81178c370de59706fef147db7a 2 parents 791da95 + 7a24550
@devdazed devdazed authored
Showing with 15 additions and 9 deletions.
  1. +14 −8 lib/pool.js
  2. +1 −1  test/thriftHostPool.js
View
22 lib/pool.js
@@ -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
2  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.
*/
var config = require('./helpers/thrift'),
Please sign in to comment.
Something went wrong with that request. Please try again.