@@ -460,26 +460,28 @@ export class Topology extends TypedEventEmitter<TopologyEvents> {
460
460
}
461
461
}
462
462
463
+ // TODO(NODE-XXXX): auto connect cannot use timeoutMS
464
+ // const timeoutMS = this.client.s.options.timeoutMS;
465
+ const serverSelectionTimeoutMS = this . client . s . options . serverSelectionTimeoutMS ;
466
+ const readPreference = options . readPreference ?? ReadPreference . primary ;
467
+ const timeoutContext = TimeoutContext . create ( {
468
+ timeoutMS : 0 ,
469
+ serverSelectionTimeoutMS,
470
+ waitQueueTimeoutMS : this . client . s . options . waitQueueTimeoutMS
471
+ } ) ;
472
+ const selectServerOptions = {
473
+ operationName : 'ping' ,
474
+ ...options ,
475
+ timeoutContext
476
+ } ;
477
+ const server = await this . selectServer (
478
+ readPreferenceServerSelector ( readPreference ) ,
479
+ selectServerOptions
480
+ ) ;
481
+
463
482
try {
464
483
const skipPingOnConnect = this . s . options [ Symbol . for ( '@@mdb.skipPingOnConnect' ) ] === true ;
465
484
if ( ! skipPingOnConnect && this . s . credentials ) {
466
- const timeoutMS = this . client . s . options . timeoutMS ;
467
- const serverSelectionTimeoutMS = this . client . s . options . serverSelectionTimeoutMS ;
468
- const readPreference = options . readPreference ?? ReadPreference . primary ;
469
- const timeoutContext = TimeoutContext . create ( {
470
- timeoutMS,
471
- serverSelectionTimeoutMS,
472
- waitQueueTimeoutMS : this . client . s . options . waitQueueTimeoutMS
473
- } ) ;
474
- const selectServerOptions = {
475
- operationName : 'ping' ,
476
- ...options ,
477
- timeoutContext
478
- } ;
479
- const server = await this . selectServer (
480
- readPreferenceServerSelector ( readPreference ) ,
481
- selectServerOptions
482
- ) ;
483
485
await server . command ( ns ( 'admin.$cmd' ) , { ping : 1 } , { timeoutContext } ) ;
484
486
stateTransition ( this , STATE_CONNECTED ) ;
485
487
this . emit ( Topology . OPEN , this ) ;
0 commit comments