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

isConnected() takes legacy path with useUnifiedTopology

    XMLWordPrintable

    Details

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

      Description

      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

       

       

       

       

       

        Attachments

          Activity

            People

            Assignee:
            matt.broadstone Matt Broadstone
            Reporter:
            wildfiction@gmail.com Guy Ellis
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: