Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: awaitable isMaster timeout must respect connectTimeoutMS #2627

Merged
merged 19 commits into from
Dec 1, 2020
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) {
emadum marked this conversation as resolved.
Show resolved Hide resolved
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);
emadum marked this conversation as resolved.
Show resolved Hide resolved

// 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