lib/mongodb/mongodb-core/lib/connection/pool.js
function _connectHandler(self) {
      return function() {
        // Assign
        var connection = this;

        // Pool destroyed stop the connection
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return connection.destroy();
        }

        // Clear out all handlers
        handlers.forEach(function(event) {
          connection.removeAllListeners(event);
        });

        // Reset reconnect id
        self.reconnectId = null;

        // Apply pool connection handlers
        connection.on('error', connectionFailureHandler(self, 'error'));
        connection.on('close', connectionFailureHandler(self, 'close'));
        connection.on('timeout', connectionFailureHandler(self, 'timeout'));
        connection.on('parseError', connectionFailureHandler(self, 'parseError'));

        // Apply any auth to the connection
        reauthenticate(self, this, function() {
          // Reset retries
          self.retriesLeft = self.options.reconnectTries;
          // Push to available connections
          self.availableConnections.push(connection);
          // Set the reconnectConnection to null
          self.reconnectConnection = null;
          // Emit reconnect event
          self.emit('reconnect', self);
          // Trigger execute to start everything up again
          _execute(self)();
        });
      };
    }
function _connectHandler(self) {
      return function() {
        // Assign
        var connection = this;

        // Pool destroyed stop the connection
        if (self.state === DESTROYED || self.state === DESTROYING) {
          return connection.destroy();
        }

        // Clear out all handlers
        handlers.forEach(function(event) {
          connection.removeAllListeners(event);
        });

        // Reset reconnect id
        self.reconnectId = null;

        // Apply pool connection handlers
        connection.on('error', connectionFailureHandler(self, 'error'));
        connection.on('close', connectionFailureHandler(self, 'close'));
        connection.on('timeout', connectionFailureHandler(self, 'timeout'));
        connection.on('parseError', connectionFailureHandler(self, 'parseError'));

        // Apply any auth to the connection
        reauthenticate(self, this, function() {
          // Reset retries
          self.retriesLeft = self.options.reconnectTries;
          // Push to available connections
          self.availableConnections.push(connection);
          // Set the reconnectConnection to null
          self.reconnectConnection = null;
          // Emit reconnect event
          self.emit('reconnect', self);
          // Trigger execute to start everything up again
          _execute(self)();
        });
      };
    }
function _connectHandler ( self ) { return function ( ) { // Assign var connection = this ; // Pool destroyed stop the connection if ( self . state === DESTROYED || self . state === DESTROYING ) { return connection . destroy ( ) ; } // Clear out all handlers handlers . forEach ( function ( event ) { connection . removeAllListeners ( event ) ; } ) ; // Reset reconnect id self . reconnectId = null ; // Apply pool connection handlers connection . on ( 'error' , connectionFailureHandler ( self , 'error' ) ) ; connection . on ( 'close' , connectionFailureHandler ( self , 'close' ) ) ; connection . on ( 'timeout' , connectionFailureHandler ( self , 'timeout' ) ) ; connection . on ( 'parseError' , connectionFailureHandler ( self , 'parseError' ) ) ; // Apply any auth to the connection reauthenticate ( self , this , function ( ) { // Reset retries self . retriesLeft = self . options . reconnectTries ; // Push to available connections self . availableConnections . push ( connection ) ; // Set the reconnectConnection to null self . reconnectConnection = null ; // Emit reconnect event self . emit ( 'reconnect' , self ) ; // Trigger execute to start everything up again _execute ( self ) ( ) ; } ) ; } ; }
Got a connect handler
Got a connect handler