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

MongoServerSelectionError when using useUnifiedTopology: true

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.4
    • Affects Version/s: 3.5.3
    • Component/s: None
    • Labels:

      I appear to be getting issues when reading from secondary members when the useUnifiedTopology flag is set to true.

       Our use case is to read some collections from secondary members to reduce strain on the primary, such as calculating stats, while other are reading from the primary

      The error is the following

       

      err { MongoServerSelectionError: Server selection timed out after 30000 ms
          at Timeout.waitQueueMember.timer.setTimeout [as _onTimeout] (/Users/paulrobinson/workspace/akero/investigate/mongoose/native_secondary/node_modules/mongodb/lib/core/sdam/topology.js:428:30)
          at ontimeout (timers.js:436:11)
          at tryOnTimeout (timers.js:300:5)
          at listOnTimeout (timers.js:263:5)
          at Timer.processTimers (timers.js:223:10)
        name: 'MongoServerSelectionError',
        reason:
         TopologyDescription {
           type: 'ReplicaSetWithPrimary',
           setName: 'rs0',
           maxSetVersion: 3,
           maxElectionId: null,
           servers:
            Map {
              'localhost:27017' => [ServerDescription],
              'localhost:27018' => [ServerDescription],
              'localhost:27016' => [ServerDescription] },
           stale: false,
           compatible: true,
           compatibilityError: null,
           logicalSessionTimeoutMinutes: 30,
           heartbeatFrequencyMS: 10000,
           localThresholdMS: 15,
           commonWireVersion: 6 },
        [Symbol(mongoErrorContextSymbol)]: {} }

       

      Here is the code and outputs

      https://gist.github.com/Niffy/d07e33e1301dd793996ba28df8b0182b

      Sorry I did not paste here, it's medium-ish in size.

      The general idea of the code is to try and read from a collection, but from the secondaries only. It attempts to read from the collection 20 times at the same time to help illustrate the bug.

      Majority of the time when useUnifiedTopology is set to true, the code will hang and throw the error.  Sometimes it will work just fine, but if you step down the primary and try again, you get the same error thrown. 

      • output-1-true.txt - You can see here it never got any results whatsoever
      • output-2-true.txt - You get some results then the error
      • output-3-false.txt - You get no errors when the useUnifiedTopology flag is set to false. This is also fine after doing a step down on the primary.

       

       

       The only way to avoid this is to set useUnifiedTopology to false.

      • mongodb driver 3.5.3
      • mongodb replica set running on 3.6.15 and 4.2.0

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            paul.robinson@akerolabs.com Paul Robinson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: