Skip to content

Conversation

simllll
Copy link
Contributor

@simllll simllll commented Aug 15, 2018

if topology.connect has an error, topology is "overwritten" which leads to an error like:

     Uncaught TypeError: Cannot read property 'close' of undefined
      at topology.connect (node_modules/mongodb/lib/operations/mongo_client_ops.js:412:16)
      at ReplSet.<anonymous> (node_modules/mongodb/lib/topologies/replset.js:364:11)
      at node_modules/mongodb-core/lib/topologies/replset.js:634:14
      at Server.<anonymous> (node_modules/mongodb-core/lib/topologies/replset.js:357:9)
      at node_modules/mongodb-core/lib/topologies/server.js:508:16
      at node_modules/mongodb-core/lib/connection/pool.js:531:18
      at process._tickCallback (internal/process/next_tick.js:61:11)

changing the function parameter to a new name, let's "force close" the old instance.

if topology.connect has an error, topology is "overwritten", changing the function parameter to a new name, let's "force close" the old instance.
@vkarpov15
Copy link
Contributor

@simllll @mbroadst I can confirm this fixes an issue that's popping up in the Mongoose tests. I looked into it and it is a minor issue that seems to pop up when you specify the replicaSet option when connecting to a standalone mongod.

const { MongoClient } = require('mongodb');

run().catch(error => console.error(error.stack));

async function run() {
  // Fails with "Cannot read property 'close' of undefined" if localhost:27017 is a standalone
  await MongoClient.connect('mongodb://localhost:27017/test', { replicaSet: 'rs', useNewUrlParser: true });
}

We can work around this for now

@mbroadst
Copy link
Member

@vkarpov15 @simllll thanks for catching this! It's strange because it should technically be the same object, but I definitely prefer the enhanced readability. We're working diligently on a fix for the change streams resume issues, so this fix here will likely make it into a patch release this week including that and updated kerberos support.

@mbroadst mbroadst merged commit 918a1e0 into mongodb:master Aug 15, 2018
vkarpov15 added a commit to Automattic/mongoose that referenced this pull request Aug 16, 2018
@simllll simllll deleted the patch-2 branch August 16, 2018 09:48
This was referenced Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants