-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 6.6.0
-
Component/s: None
Use Case
As a MongoDB user who is calling MongoClient.connect on an un-selectable cluster
I want MongoClient.connect to hold the Node.js process open until serverSelectionTimeoutMS expires
So that I can see the rejected error.
The new Timeout abstraction unref-s it's timer which may make sense for CSOT. On your very first connect call the serverSelection ref-ed setTimeout call is what keeps Node.js open.
User Impact
- The following sample code exits immediately with "Warning: Detected unsettled top-level await"
import { MongoClient } from 'mongodb'; // real set name: repl0 const cs = 'mongodb://127.0.0.1:27017,127.0.0.1:27018,127.0.0.1:27019/&replicaSet=asdf'; process.on('exit', () => console.log('exiting')); const client = await MongoClient.connect(cs); console.log('connected'); await client.close();
Dependencies
- serverSelectionTimeoutMS logic
- Timeout ref/unref
Unknowns
- None
Acceptance Criteria
Implementation Requirements
- Ref the timer in Timeout
- If it is possible only do this when we are connecting for the first time? (check the MongoClient) otherwise do it always and revisit ref-ing / clearing for CSOT
Testing Requirements
- Determine: What is the best programmatic way to determine if Node.js would exit?
process _activeHandles?process.on('beforeExit')
- Assert MongoClient.connect keeps Node.js running until it succeeds or fails.
Documentation Requirements
- None
Follow Up Requirements
- Consider refactoring auto-connect: monitors should be "always on". Is this caused by the process.nextTick that surrounds requestCheck? if we called requestCheck directly then would server selection have created sockets thus keeping Node open?
- Add testing to verify that this behaviour does not return in subsequent changes (NODE-6152)
- is depended on by
-
MONGOSH-1774 Update driver to 6.6.1
- Closed
-
COMPASS-7912 Investigate changes in NODE-6151: MongoClient connect does not keep Node.js running
- Closed
- is related to
-
NODE-6152 Add testing to ensure that MongoClient.connect will hold the event loop open until it resolves
- Backlog