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

No primary server available

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.0.53, 2.1.2
    • Affects Version/s: None
    • Component/s: None
    • Environment:
      Amazon Linux, 64 bit. Nodejs version 4.2.1, mongoDB version 3.0.7 with mongoose 4.2.8.

      I have an issue that is rather difficult to debug, and was wondering if anyone sees anything wrong with my configuration. I posted an issue in the mongoose github repo (https://github.com/Automattic/mongoose/issues/3634) but have not had any luck there, was hoping someone could help me figure this out.

      ```
      Error no primary server available
      ```

      Nodejs version `4.2.1` and mongoDB version `3.0.7` with mongoose `4.2.8`.

      This seems to happen randomly and will open many connection until I finally restart the node process. *The cluster is healthy at all times during this error*. This error happens hundreds of times per hour. There does not seem to be any consistency as to when the error will begin. For example, it occurs when the cluster is operating normally and no changes to the primary have been made.

      This is what the db stats look like. As you can see the number of connections will steadily increase. If I kill the node process and start a new one everything is fine.

      See attached image.

      Config

      ```
      // Connect
      mongoose.connect(config.mongo.connectionString, {
      server: {
      socketOptions:

      { socketTimeoutMS: 5 * 60 * 1000, keepAlive: 1 }

      },
      replset: {
      socketOptions:

      { socketTimeoutMS: 5 * 60 * 1000, keepAlive: 1 }

      }
      });
      ```

      Connection String

      ```
      mongodb://username:password@mongo-1.cz.0200.mongodbdns.com:27000,mongo-2.cz.0200.mongodbdns.com:27000,mongo-3.cz.0200.mongodbdns.com:27000/dbase
      ```

      Stack trace

      ```
      node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:860 pickServer
      node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/replset.js:437 command
      node_modules/mongoose/node_modules/mongodb/lib/replset.js:392 command
      node_modules/mongoose/node_modules/mongodb/lib/db.js:284 executeCommand
      node_modules/mongoose/node_modules/mongodb/lib/db.js:307 command
      node_modules/mongoose/node_modules/mongodb/lib/collection.js:2340 findAndModify
      node_modules/mongoose/node_modules/mongodb/lib/collection.js:2278 findAndModify
      node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:136 (anonymous function) [as findAndModify]
      node_modules/mongoose/node_modules/mquery/lib/collection/node.js:79 findAndModify
      node_modules/mongoose/lib/query.js:1833 _findAndModify
      node_modules/mongoose/lib/query.js:1621 _findOneAndUpdate
      node_modules/mongoose/node_modules/kareem/index.js:156 none
      node_modules/mongoose/node_modules/kareem/index.js:18 none
      node.js:417doNTCallback0
      node.js:387_tickDomainCallback
      ```

      While connections are on the rise the status of the cluster is healthy:

      ```
      {
      "set" : "mongo2",
      "date" : ISODate("2015-12-04T23:39:32.520Z"),
      "myState" : 1,
      "members" : [

      { "_id" : 6, "name" : "mongo-8.loc.0600.mongodbdns.com:27000", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 444053, "optime" : Timestamp(1449272372, 32), "optimeDate" : ISODate("2015-12-04T23:39:32Z"), "lastHeartbeat" : ISODate("2015-12-04T23:39:32.507Z"), "lastHeartbeatRecv" : ISODate("2015-12-04T23:39:31.442Z"), "pingMs" : 0, "syncingTo" : "mongo-9.loc.0600.mongodbdns.com:27000", "configVersion" : 29 }

      ,

      { "_id" : 7, "name" : "mongo-9.loc.0600.mongodbdns.com:27000", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 444056, "optime" : Timestamp(1449272372, 39), "optimeDate" : ISODate("2015-12-04T23:39:32Z"), "electionTime" : Timestamp(1449097485, 1), "electionDate" : ISODate("2015-12-02T23:04:45Z"), "configVersion" : 29, "self" : true }

      ,

      { "_id" : 8, "name" : "mongo-10.loc.0600.mongodbdns.com:27000", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 444053, "optime" : Timestamp(1449272371, 111), "optimeDate" : ISODate("2015-12-04T23:39:31Z"), "lastHeartbeat" : ISODate("2015-12-04T23:39:31.904Z"), "lastHeartbeatRecv" : ISODate("2015-12-04T23:39:30.903Z"), "pingMs" : 2, "syncingTo" : "mongo-8.loc.0600.mongodbdns.com:27000", "configVersion" : 29 }

      ],
      "ok" : 1
      }
      ```

      I have been outputting mongoose connection events, and it appears to try and reconnect a lot.

      ```
      [4:30] Mongoose event: fullsetup
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: open
      [4:30] Mongoose event: connected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: reconnected
      [4:30] Mongoose event: fullsetup
      [4:30] Mongoose event: connected
      [4:30] Mongoose event: open
      [4:30]
      {
      "err":

      { "name": "MongoError", "message": "no primary server available" }

      }
      ```

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            chriszieba Chris Zieba
            Votes:
            11 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: