Skip to content

Commit

Permalink
fix: socket timeout for handshake should be connectTimeoutMS
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jan 4, 2020
1 parent 27fbe56 commit c83af9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/core/connection/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ function performInitialHandshake(conn, options, _callback) {
getSaslSupportedMechs(options)
);

const handshakeOptions = Object.assign({}, options);

// The handshake technically is a monitoring check, so its socket timeout should be connectTimeoutMS
if (options.connectTimeoutMS || options.connectionTimeout) {
handshakeOptions.socketTimeout = options.connectTimeoutMS || options.connectionTimeout;
}

const start = new Date().getTime();
runCommand(conn, 'admin.$cmd', handshakeDoc, options, (err, ismaster) => {
runCommand(conn, 'admin.$cmd', handshakeDoc, handshakeOptions, (err, ismaster) => {
if (err) {
callback(err);
return;
Expand Down Expand Up @@ -235,7 +242,11 @@ function makeConnection(family, options, cancellationToken, _callback) {
typeof options.keepAliveInitialDelay === 'number' ? options.keepAliveInitialDelay : 300000;
const noDelay = typeof options.noDelay === 'boolean' ? options.noDelay : true;
const connectionTimeout =
typeof options.connectionTimeout === 'number' ? options.connectionTimeout : 30000;
typeof options.connectionTimeout === 'number'
? options.connectionTimeout
: typeof options.connectTimeoutMS === 'number'
? options.connectTimeoutMS
: 30000;
const socketTimeout = typeof options.socketTimeout === 'number' ? options.socketTimeout : 360000;
const rejectUnauthorized =
typeof options.rejectUnauthorized === 'boolean' ? options.rejectUnauthorized : true;
Expand Down
1 change: 1 addition & 0 deletions lib/core/sdam/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Monitor extends EventEmitter {
connectionType: Connection
},
server.s.options,
this.options,

// force BSON serialization options
{
Expand Down

0 comments on commit c83af9a

Please sign in to comment.