Details
-
Improvement
-
Status: Closed
-
Major - P3
-
Resolution: Done
-
None
-
None
-
None
-
2
-
Not Needed
Description
In light of handling CTRL-C in the shell we observed that using `MongoClient.close(...)` does not close all connections that were opened by the client if a connection is still running an operation.
Take the following script as an example:
const MongoClient = require('mongodb').MongoClient;
|
(async() => {
|
console.log('Connecting...');
|
const client = await MongoClient.connect('mongodb://localhost:30001');
|
const db = client.db('test');
|
db.collection('ctrlc').find({ $where: 'while(true) {}' }).toArray().then(r => console.log(r));
|
setTimeout(async () => {
|
await client.close(true);
|
console.log('Closed...');
|
setInterval(() => {
|
console.log('alive', new Date().toISOString());
|
}, 10_000);
|
}, 1000);
|
})().catch(e => process.nextTick(() => { console.log(e); process.exit(1); }));
|
The find operation will be running in the background and continues even after calling client.close(...) (which does not throw an error). The socket is still kept open until I terminate the process.
(NOTE: the example above only works as designed when there is a collection called ctrlc with at least one document)
This seems to be a regression in 4.x.
Attachments
Issue Links
- related to
-
NODE-3263 Calling close() does not terminate all connections
-
- Blocked
-