isConnected() takes legacy path with useUnifiedTopology

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 3.3.4
    • Affects Version/s: 3.3.2
    • Component/s: MongoDB 3.2
    • Environment:
      Not using Mongoose. Not transpiling the driver.
    • None
    • None
    • None
    • None
    • None
    • None

      Using the Node Driver, I create a connection with the "useUnifiedTopology" option set to true with a snippet like this.

        const { url } = databaseConfig;  
        const databaseConnection = new MongoClient(url, {
           useUnifiedTopology: true,
           useNewUrlParser: true,
         });
         return databaseConnection.connect();
      

       

      Later I close the connection and check to see if it's closed:

      await client.close();
      expect(client.isConnected()).toBe(false); // this fails because it's true

      When tracing the isConnected() call it ends up returning true (always) from here:

      https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/core/sdam/topology.js#L663

      If I change the useUnifiedTopology to false and leave everything else the same then the code works as expected and this line is hit instead:

      https://github.com/mongodb/node-mongodb-native/blob/dc70c2de7d3dae2617708c45a1ea695d131e15f3/lib/topologies/topology_base.js#L340

       

       

       

       

       

              Assignee:
              Matt Broadstone
              Reporter:
              Guy Ellis
              None
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: