Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fix hanging query

relates to #537
  • Loading branch information...
commit f632653330d2fb88617ab18e540100ec37b21473 1 parent 6388f51
Aaron Heckmann authored March 30, 2012

Showing 1 changed file with 15 additions and 14 deletions. Show diff stats Hide diff stats

  1. 29  lib/mongodb/db.js
29  lib/mongodb/db.js
@@ -1435,20 +1435,21 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
1435 1435
         // Get number of auths we need to execute
1436 1436
         var numberOfAuths = _self.auths.length;
1437 1437
         // Apply all auths
1438  
-        for(var i = 0; i < _self.auths.length; i++) {          
1439  
-          _self.authenticate(_self.auths[i].username, _self.auths[i].password, function(err, authenticated) {              
  1438
+        for(var i = 0; i < _self.auths.length; i++) {
  1439
+          _self.authenticate(_self.auths[i].username, _self.auths[i].password, function(err, authenticated) {
1440 1440
             numberOfAuths = numberOfAuths - 1;
1441  
-            
  1441
+
1442 1442
             // If we have no more authentications to replay
1443  
-            if(numberOfAuths == 0) {                                
  1443
+            if(numberOfAuths == 0) {
1444 1444
               if(err != null || !authenticated) {
1445 1445
                 if(typeof _callback == 'function') _callback(err, null);
1446 1446
                 return;
1447 1447
               } else {
1448 1448
                 // Execute command
1449  
-                command(_self, _db_command, _options, function(err, result) {
1450  
-                  // Peform the command callback
1451  
-                  if(typeof _callback == 'function') _callback(err, result);
  1449
+                command(_self, _db_command, _options, _callback);
  1450
+
  1451
+                // Execute any backed up commands
  1452
+                process.nextTick(function() {
1452 1453
                   // Execute any backed up commands
1453 1454
                   while(_self.commands.length > 0) {
1454 1455
                     // Fetch the command
@@ -1464,13 +1465,13 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
1464 1465
               }
1465 1466
             }
1466 1467
           });
1467  
-        }        
  1468
+        }
1468 1469
       } else if(err == null && _self.serverConfig.isConnected() == true) {
1469 1470
         _self._state = 'connected';
1470 1471
         // Execute command
1471  
-        command(_self, _db_command, _options, function(err, result) {
1472  
-          // Peform the command callback
1473  
-          _callback(err, result);
  1472
+        command(_self, _db_command, _options, _callback);
  1473
+
  1474
+        process.nextTick(function() {
1474 1475
           // Execute any backed up commands
1475 1476
           while(_self.commands.length > 0) {
1476 1477
             // Fetch the command
@@ -1482,16 +1483,16 @@ var __retryCommandOnFailure = function(self, retryInMilliseconds, numberOfTimes,
1482 1483
               __executeInsertCommand(_self, command['db_command'], command['options'], command['callback']);
1483 1484
             }
1484 1485
           }
1485  
-        });                            
  1486
+        });
1486 1487
       } else {
1487 1488
         _self._state = 'connecting';
1488 1489
         // Force close the current connections
1489 1490
         _self.serverConfig.close(function(err) {
1490 1491
           // Retry the connect
1491 1492
           setTimeout(function() {
1492  
-            retryFunction(_self, _numberOfRetriesDone, _retryInMilliseconds, _numberOfTimes, _command, _db_command, _options, _callback);            
  1493
+            retryFunction(_self, _numberOfRetriesDone, _retryInMilliseconds, _numberOfTimes, _command, _db_command, _options, _callback);
1493 1494
           }, _retryInMilliseconds);
1494  
-        });        
  1495
+        });
1495 1496
       }
1496 1497
     });
1497 1498
   };

0 notes on commit f632653

Please sign in to comment.
Something went wrong with that request. Please try again.