-
Type: Investigation
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Not Needed
-
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?
- 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?
- depends on
-
NODE-6151 MongoClient connect does not keep Node.js running
- Closed