Permalink
Browse files

fix hanging query

relates to #537
  • Loading branch information...
1 parent 6388f51 commit f632653330d2fb88617ab18e540100ec37b21473 @aheckmann aheckmann committed Mar 30, 2012
Showing with 15 additions and 14 deletions.
  1. +15 −14 lib/mongodb/db.js
View
29 lib/mongodb/db.js
@@ -1435,20 +1435,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
@@ -1464,13 +1465,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
@@ -1482,16 +1483,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 f632653

Please sign in to comment.