@@ -111,8 +111,15 @@ function performInitialHandshake(conn, options, _callback) {
111111 getSaslSupportedMechs ( options )
112112 ) ;
113113
114+ const handshakeOptions = Object . assign ( { } , options ) ;
115+
116+ // The handshake technically is a monitoring check, so its socket timeout should be connectTimeoutMS
117+ if ( options . connectTimeoutMS || options . connectionTimeout ) {
118+ handshakeOptions . socketTimeout = options . connectTimeoutMS || options . connectionTimeout ;
119+ }
120+
114121 const start = new Date ( ) . getTime ( ) ;
115- runCommand ( conn , 'admin.$cmd' , handshakeDoc , options , ( err , ismaster ) => {
122+ runCommand ( conn , 'admin.$cmd' , handshakeDoc , handshakeOptions , ( err , ismaster ) => {
116123 if ( err ) {
117124 callback ( err ) ;
118125 return ;
@@ -235,7 +242,11 @@ function makeConnection(family, options, cancellationToken, _callback) {
235242 typeof options . keepAliveInitialDelay === 'number' ? options . keepAliveInitialDelay : 300000 ;
236243 const noDelay = typeof options . noDelay === 'boolean' ? options . noDelay : true ;
237244 const connectionTimeout =
238- typeof options . connectionTimeout === 'number' ? options . connectionTimeout : 30000 ;
245+ typeof options . connectionTimeout === 'number'
246+ ? options . connectionTimeout
247+ : typeof options . connectTimeoutMS === 'number'
248+ ? options . connectTimeoutMS
249+ : 30000 ;
239250 const socketTimeout = typeof options . socketTimeout === 'number' ? options . socketTimeout : 360000 ;
240251 const rejectUnauthorized =
241252 typeof options . rejectUnauthorized === 'boolean' ? options . rejectUnauthorized : true ;
0 commit comments