Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3252

ReplSet getting stuck in disconnected state

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.6.7
    • Affects Version/s: None
    • Component/s: None
    • Not Needed

      We run the nodejs mongo driver in the following environments

      • fastify server
      • docker lts-alpine image
      • aws ecs fargate
      • azure container instances

      Our logs are constantly reporting the following error:

      {{

      { "level": 30, "time": 1620059246339, "pid": 1, "hostname": "ip-10-0-34-147.ec2.internal", "type": "error", "message": "Pool with id [1] failed attempted illegal state transition from [disconnected] to [connected] only following state allowed [[ 'connecting', 'destroyed', 'disconnected' ]]", "className": "ReplSet", "date": 1620059246339, "msg": "[ERROR-ReplSet:1] 1620059246339 Pool with id [1] failed attempted illegal state transition from [disconnected] to [connected] only following state allowed [[ 'connecting', 'destroyed', 'disconnected' ]]" }

      }}

       

      Looking at the code i think i can eyeball the issue

      https://github.com/mongodb/node-mongodb-native/blob/be269b1c537a091cbc97b8f06777860a8f27e828/lib/core/topologies/replset.js#L33-L40 

      function stateTransition(self, newState) {
      {{ var legalTransitions = {}}
        disconnected: [CONNECTING, DESTROYED, DISCONNECTED],
        connecting: [CONNECTING, DESTROYED, CONNECTED, DISCONNECTED],
        connected: [CONNECTED, DISCONNECTED, DESTROYED, UNREFERENCED],
        unreferenced: [UNREFERENCED, DESTROYED],
        destroyed: [DESTROYED]
      {{ };}}

      But there exists the following caller still

      https://github.com/mongodb/node-mongodb-native/blob/be269b1c537a091cbc97b8f06777860a8f27e828/lib/core/topologies/replset.js#L555-L571

      if (
      {{ self.state === DISCONNECTED &&}}
      {{ ((self.s.replicaSetState.hasSecondary() &&}}
      {{ self.s.options.secondaryOnlyConnectionAllowed) ||}}
      {{ self.s.replicaSetState.hasPrimary())}}
      {{ ) {}}
        stateTransition(self, CONNECTED);// Rexecute any stalled operation
        rexecuteOperations(self);// Emit connected sign
        process.nextTick(function() {
        self.emit('reconnect', self);
      {{ });}}
      {{ }}}

       

       

       

       

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            andres.olave@velocitycareerlabs.com Andres Olave
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: