-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
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.
- depends on
-
NODE-5221 Design client close() behavior
- Backlog
- is depended on by
-
MONGOSH-640 Graceful handling of Ctrl-C
- Closed
- is related to
-
NODE-2469 Add a message to unref
- Closed
-
NODE-4039 Leaking an async hook
- Closed
-
NODE-4040 Investigate NODE-4039 - Leaking an async hook
- Closed
-
NODE-4344 Investigate Node-3263: Calling close() does not terminate all connections
- Closed
- links to
- mentioned in
-
Page Loading...