Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Connect fix #78

Merged
merged 3 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
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'),
Something went wrong with that request. Please try again.