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

Enabling useUnifiedTopology results in stack overflow when connecting to uninitialized replica set

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

      Steps to reproduce:
      1. Start a single-node replica set but do not initialize it.
      mongod --replSet repro --port 37017 --dbpath ./data/db --logpath ./data/mongodb.log --fork
      2. Run the following Node.js code (using Node.js Driver 3.3.4):

      const MongoClient = require('mongodb').MongoClient;
      
      const url = 'mongodb://localhost:37017';
      
      const client = new MongoClient(url, {useUnifiedTopology:true});
      
      client.connect((err, client) => {
        client.db('admin')
              .command({replSetInitiate: { _id: 'repro', members: [{_id: 0, host: 'localhost:37017'}] }},
                       (err) => console.log(err));
      });
      

      This results in a stack overflow:

      $ node test.js
      /Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/core/sdam/topology.js:435
            process.hrtime(),
            ^
      
      RangeError: Maximum call stack size exceeded
          at NativeTopology.selectServer (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/core/sdam/topology.js:435:7)
          at selectServerForSessionSupport (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:186:12)
          at executeOperation (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:38:12)
          at /Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:192:5
          at /Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/core/sdam/topology.js:444:9
          at selectServers (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/core/sdam/topology.js:877:12)
          at NativeTopology.selectServer (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/core/sdam/topology.js:431:5)
          at selectServerForSessionSupport (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:186:12)
          at executeOperation (/Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:38:12)
          at /Users/james/Documents/mongodb-cases/00618581/repro/node_modules/mongodb/lib/operations/execute_operation.js:192:5
      

      If you remove useUnifiedTopology:true, the code works as expected and initializes the replica set.

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: