@@ -111,8 +111,15 @@ function performInitialHandshake(conn, options, _callback) {
111
111
getSaslSupportedMechs ( options )
112
112
) ;
113
113
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
+
114
121
const start = new Date ( ) . getTime ( ) ;
115
- runCommand ( conn , 'admin.$cmd' , handshakeDoc , options , ( err , ismaster ) => {
122
+ runCommand ( conn , 'admin.$cmd' , handshakeDoc , handshakeOptions , ( err , ismaster ) => {
116
123
if ( err ) {
117
124
callback ( err ) ;
118
125
return ;
@@ -235,7 +242,11 @@ function makeConnection(family, options, cancellationToken, _callback) {
235
242
typeof options . keepAliveInitialDelay === 'number' ? options . keepAliveInitialDelay : 300000 ;
236
243
const noDelay = typeof options . noDelay === 'boolean' ? options . noDelay : true ;
237
244
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 ;
239
250
const socketTimeout = typeof options . socketTimeout === 'number' ? options . socketTimeout : 360000 ;
240
251
const rejectUnauthorized =
241
252
typeof options . rejectUnauthorized === 'boolean' ? options . rejectUnauthorized : true ;
0 commit comments