Permalink
Browse files

Merge commit 'f632653330d2fb88617ab18e540100ec37b21473'

  • Loading branch information...
2 parents b2f0874 + f632653 commit 451f8f08207bcabd91571fb2695de89ffdc032f0 @christkv committed Apr 1, 2012
Showing with 15 additions and 14 deletions.
  1. +15 −14 lib/mongodb/db.js
View
@@ -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
@@ -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
@@ -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);
- });
+ });
}
});
};

0 comments on commit 451f8f0

Please sign in to comment.