-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 3.6.6
-
Component/s: None
-
Environment:Xubuntu 18.04, MongoDB server 4.4.0, Node.js 14.4.0
-
Empty show more show less
-
Not Needed
The below script prints "Got close" twice:
'use strict'; const { MongoClient } = require('mongodb'); void async function main() { const client = await MongoClient.connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true }); client.on('close', () => console.log('Got close')); await client.close(); await new Promise(resolve => setTimeout(resolve, 100)); console.log('Done'); }();
It looks like `MongoClient#close()` emits 'close' once: https://github.com/mongodb/node-mongodb-native/blob/2b18411d2f57e06d11262d5a308c56a9f561789e/lib/mongo_client.js#L284 , but then the Topology class also bubbles up its 'close' event to the MongoClient instance: https://github.com/mongodb/node-mongodb-native/blob/2b18411d2f57e06d11262d5a308c56a9f561789e/lib/operations/connect.js#L207