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

useUnifiedTopology breaks `force` option for `close()`

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.3
    • Affects Version/s: 3.3.2
    • Component/s: None
    • Labels:
    • Environment:
      MongoDB driver 3.3.2, local replica set running server 4.0.6. No transpilers, no Mongoose.

      The below script succeeds when using `useUnifiedTopology`, but reports a "server instance pool was destroyed" error if `useUnifiedTopology` is off.

      const { MongoClient } = require('mongodb');
      
      run().catch(err => console.log(err));
      
      async function run() {
        const client = await MongoClient.connect('mongodb://localhost:27017/test', {
          useNewUrlParser: true,
          useUnifiedTopology: true
        });
        const db = client.db();
      
        await client.close(true);
        await db.collection('Test').insertOne({ x: 1 });
      
        console.log('done');
      }
      

      It looks like the unified topology.js doesn't do anything with the `force` option: https://github.com/mongodb/node-mongodb-native/blob/f6e854ceb7644eefd71789e084f4c46e3e2b4da3/lib/core/sdam/topology.js#L277-L278

      `db.isMaster()` output:

      {
      	"hosts" : [
      		"localhost:27017",
      		"localhost:27018",
      		"localhost:27019"
      	],
      	"setName" : "rs",
      	"setVersion" : 1,
      	"ismaster" : true,
      	"secondary" : false,
      	"primary" : "localhost:27017",
      	"me" : "localhost:27017",
      	"electionId" : ObjectId("7fffffff0000000000000001"),
      	"lastWrite" : {
      		"opTime" : {
      			"ts" : Timestamp(1568041368, 1),
      			"t" : NumberLong(1)
      		},
      		"lastWriteDate" : ISODate("2019-09-09T15:02:48Z"),
      		"majorityOpTime" : {
      			"ts" : Timestamp(1568041368, 1),
      			"t" : NumberLong(1)
      		},
      		"majorityWriteDate" : ISODate("2019-09-09T15:02:48Z")
      	},
      	"maxBsonObjectSize" : 16777216,
      	"maxMessageSizeBytes" : 48000000,
      	"maxWriteBatchSize" : 100000,
      	"localTime" : ISODate("2019-09-09T15:02:52.734Z"),
      	"logicalSessionTimeoutMinutes" : 30,
      	"minWireVersion" : 0,
      	"maxWireVersion" : 7,
      	"readOnly" : false,
      	"ok" : 1,
      	"operationTime" : Timestamp(1568041368, 1),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1568041368, 1),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      

            Assignee:
            matt.broadstone@mongodb.com Matt Broadstone
            Reporter:
            val@karpov.io Valeri Karpov
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: