Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions lib/core/sdam/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,19 @@ function checkServer(monitor, callback) {
const topologyVersion = monitor[kServer].description.topologyVersion;
const isAwaitable = topologyVersion != null;

const cmd = isAwaitable
? { ismaster: true, maxAwaitTimeMS, topologyVersion: makeTopologyVersion(topologyVersion) }
: { ismaster: true };

const options = isAwaitable
? { socketTimeout: connectTimeoutMS + maxAwaitTimeMS, exhaustAllowed: true }
: { socketTimeout: connectTimeoutMS };

if (isAwaitable && monitor[kRTTPinger] == null) {
monitor[kRTTPinger] = new RTTPinger(monitor[kCancellationToken], monitor.connectOptions);
const cmd = { ismaster: true };
const options = { socketTimeout: connectTimeoutMS };

if (isAwaitable) {
cmd.maxAwaitTimeMS = maxAwaitTimeMS;
cmd.topologyVersion = makeTopologyVersion(topologyVersion);
if (connectTimeoutMS) {
options.socketTimeout = connectTimeoutMS + maxAwaitTimeMS;
}
options.exhaustAllowed = true;
if (monitor[kRTTPinger] == null) {
monitor[kRTTPinger] = new RTTPinger(monitor[kCancellationToken], monitor.connectOptions);
}
}

monitor[kConnection].command('admin.$cmd', cmd, options, (err, result) => {
Expand Down
22 changes: 22 additions & 0 deletions test/functional/mongo_client_options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ describe('MongoClient Options', function() {
});
});

it('NODE-2874: connectTimeoutMS=0 causes monitoring to time out', function(done) {
Comment thread
emadum marked this conversation as resolved.
Outdated
const heartbeatFrequencyMS = 500;
const client = this.configuration.newClient({
connectTimeoutMS: 0, // no connect timeout
heartbeatFrequencyMS // fast 500ms heartbeat
});
client.connect(() => {
// success after 5 heartbeats
const success = setTimeout(() => client.close(done), heartbeatFrequencyMS * 5);
Comment thread
emadum marked this conversation as resolved.
Outdated

// fail on first error
const listener = ev => {
if (ev.newDescription.error) {
clearTimeout(success);
client.removeListener('serverDescriptionChanged', listener);
client.close(() => done(ev.newDescription.error));
}
};
client.on('serverDescriptionChanged', listener);
});
});

/**
* @ignore
*/
Expand Down