Skip to content

Commit

Permalink
Merge commit 'f632653330d2fb88617ab18e540100ec37b21473'
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Apr 1, 2012
2 parents b2f0874 + f632653 commit 451f8f0
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/mongodb/db.js
Expand Up @@ -1437,20 +1437,21 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
// Get number of auths we need to execute
var numberOfAuths = _self.auths.length;
// Apply all auths
for(var i = 0; i < _self.auths.length; i++) {
_self.authenticate(_self.auths[i].username, _self.auths[i].password, function(err, authenticated) {
for(var i = 0; i < _self.auths.length; i++) {
_self.authenticate(_self.auths[i].username, _self.auths[i].password, function(err, authenticated) {
numberOfAuths = numberOfAuths - 1;

// If we have no more authentications to replay
if(numberOfAuths == 0) {
if(numberOfAuths == 0) {
if(err != null || !authenticated) {
if(typeof _callback == 'function') _callback(err, null);
return;
} else {
// Execute command
command(_self, _db_command, _options, function(err, result) {
// Peform the command callback
if(typeof _callback == 'function') _callback(err, result);
command(_self, _db_command, _options, _callback);

// Execute any backed up commands
process.nextTick(function() {
// Execute any backed up commands
while(_self.commands.length > 0) {
// Fetch the command
Expand All @@ -1466,13 +1467,13 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
}
}
});
}
}
} else if(err == null && _self.serverConfig.isConnected() == true) {
_self._state = 'connected';
// Execute command
command(_self, _db_command, _options, function(err, result) {
// Peform the command callback
_callback(err, result);
command(_self, _db_command, _options, _callback);

process.nextTick(function() {
// Execute any backed up commands
while(_self.commands.length > 0) {
// Fetch the command
Expand All @@ -1484,16 +1485,16 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
__executeInsertCommand(_self, command['db_command'], command['options'], command['callback']);
}
}
});
});
} else {
_self._state = 'connecting';
// Force close the current connections
_self.serverConfig.close(function(err) {
// Retry the connect
setTimeout(function() {
retryFunction(_self, _numberOfRetriesDone, _retryInMilliseconds, _numberOfTimes, _command, _db_command, _options, _callback);
retryFunction(_self, _numberOfRetriesDone, _retryInMilliseconds, _numberOfTimes, _command, _db_command, _options, _callback);
}, _retryInMilliseconds);
});
});
}
});
};
Expand Down

0 comments on commit 451f8f0

Please sign in to comment.