lib/mongodb/mongodb-core/lib/connection/pool.js
function authenticateStragglers(self, connection, callback) {
      // Get any non authenticated connections
      var connections = self.nonAuthenticatedConnections.slice(0);
      var nonAuthenticatedConnections = self.nonAuthenticatedConnections;
      self.nonAuthenticatedConnections = [];

      // Establish if the connection need to be authenticated
      // Add to authentication list if
      // 1. we were in an authentication process when the operation was executed
      // 2. our current authentication timestamp is from the workItem one, meaning an auth has happened
      if (
        connection.workItems.length === 1 &&
        (connection.workItems[0].authenticating === true ||
          (typeof connection.workItems[0].authenticatingTimestamp === 'number' &&
            connection.workItems[0].authenticatingTimestamp !== self.authenticatingTimestamp))
      ) {
        // Add connection to the list
        connections.push(connection);
      }

      // No connections need to be re-authenticated
      if (connections.length === 0) {
        // Release the connection back to the pool
        moveConnectionBetween(connection, self.inUseConnections, self.availableConnections);
        // Finish
        return callback();
      }

      // Apply re-authentication to all connections before releasing back to pool
      var connectionCount = connections.length;
      // Authenticate all connections
      for (var i = 0; i < connectionCount; i++) {
        reauthenticate(self, connections[i], function() {
          connectionCount = connectionCount - 1;

          if (connectionCount === 0) {
            // Put non authenticated connections in available connections
            self.availableConnections = self.availableConnections.concat(
              nonAuthenticatedConnections
            );
            // Release the connection back to the pool
            moveConnectionBetween(connection, self.inUseConnections, self.availableConnections);
            // Return
            callback();
          }
        });
      }
    }
function authenticateStragglers(self, connection, callback) {
      // Get any non authenticated connections
      var connections = self.nonAuthenticatedConnections.slice(0);
      var nonAuthenticatedConnections = self.nonAuthenticatedConnections;
      self.nonAuthenticatedConnections = [];

      // Establish if the connection need to be authenticated
      // Add to authentication list if
      // 1. we were in an authentication process when the operation was executed
      // 2. our current authentication timestamp is from the workItem one, meaning an auth has happened
      if (
        connection.workItems.length === 1 &&
        (connection.workItems[0].authenticating === true ||
          (typeof connection.workItems[0].authenticatingTimestamp === 'number' &&
            connection.workItems[0].authenticatingTimestamp !== self.authenticatingTimestamp))
      ) {
        // Add connection to the list
        connections.push(connection);
      }

      // No connections need to be re-authenticated
      if (connections.length === 0) {
        // Release the connection back to the pool
        moveConnectionBetween(connection, self.inUseConnections, self.availableConnections);
        // Finish
        return callback();
      }

      // Apply re-authentication to all connections before releasing back to pool
      var connectionCount = connections.length;
      // Authenticate all connections
      for (var i = 0; i < connectionCount; i++) {
        reauthenticate(self, connections[i], function() {
          connectionCount = connectionCount - 1;

          if (connectionCount === 0) {
            // Put non authenticated connections in available connections
            self.availableConnections = self.availableConnections.concat(
              nonAuthenticatedConnections
            );
            // Release the connection back to the pool
            moveConnectionBetween(connection, self.inUseConnections, self.availableConnections);
            // Return
            callback();
          }
        });
      }
    }
function authenticateStragglers ( self , connection , callback ) { // Get any non authenticated connections var connections = self . nonAuthenticatedConnections . slice ( 0 ) ; var nonAuthenticatedConnections = self . nonAuthenticatedConnections ; self . nonAuthenticatedConnections = [ ] ; // Establish if the connection need to be authenticated // Add to authentication list if // 1. we were in an authentication process when the operation was executed // 2. our current authentication timestamp is from the workItem one, meaning an auth has happened if ( connection . workItems . length === 1 && ( connection . workItems [ 0 ] . authenticating === true || ( typeof connection . workItems [ 0 ] . authenticatingTimestamp === 'number' && connection . workItems [ 0 ] . authenticatingTimestamp !== self . authenticatingTimestamp ) ) ) { // Add connection to the list connections . push ( connection ) ; } // No connections need to be re-authenticated if ( connections . length === 0 ) { // Release the connection back to the pool moveConnectionBetween ( connection , self . inUseConnections , self . availableConnections ) ; // Finish return callback ( ) ; } // Apply re-authentication to all connections before releasing back to pool var connectionCount = connections . length ; // Authenticate all connections for ( var i = 0 ; i < connectionCount ; i ++ ) { reauthenticate ( self , connections [ i ] , function ( ) { connectionCount = connectionCount - 1 ; if ( connectionCount === 0 ) { // Put non authenticated connections in available connections self . availableConnections = self . availableConnections . concat ( nonAuthenticatedConnections ) ; // Release the connection back to the pool moveConnectionBetween ( connection , self . inUseConnections , self . availableConnections ) ; // Return callback ( ) ; } } ) ; } }
Authenticate any straggler connections
Authenticate any straggler connections