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(NODE-6171): RTT set to zero when serverMonitoringMode=stream #4110

Merged
merged 12 commits into from
May 15, 2024
Next Next commit
fix bug
  • Loading branch information
W-A-James committed May 14, 2024
commit e5019482ca087f20b0886a2ebcadf439e2b637cd
11 changes: 6 additions & 5 deletions src/sdam/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
return this.rttSampler.min();
}

get latestRtt(): number {
return this.rttSampler.last ?? 0; // FIXME: Check if this is acceptable
get latestRtt(): number | null {
return this.rttSampler.last; // FIXME: Check if this is acceptable
}

addRttSample(rtt: number) {
Expand Down Expand Up @@ -304,7 +304,8 @@ function checkServer(monitor: Monitor, callback: Callback<Document | null>) {
}

// NOTE: here we use the latestRtt as this measurement corresponds with the value
// obtained for this successful heartbeat
// obtained for this successful heartbeat, if there is no latestRtt, then we calculate the
// duration
const duration =
isAwaitable && monitor.rttPinger
? monitor.rttPinger.latestRtt ?? calculateDurationInMs(start)
Expand Down Expand Up @@ -498,7 +499,7 @@ export class RTTPinger {
this[kCancellationToken] = monitor[kCancellationToken];
this.closed = false;
this.monitor = monitor;
this.latestRtt = monitor.latestRtt;
this.latestRtt = monitor.latestRtt ?? undefined;

const heartbeatFrequencyMS = monitor.options.heartbeatFrequencyMS;
this[kMonitorId] = setTimeout(() => this.measureRoundTripTime(), heartbeatFrequencyMS);
Expand Down Expand Up @@ -565,7 +566,7 @@ export class RTTPinger {
connection.serverApi?.version || connection.helloOk ? 'hello' : LEGACY_HELLO_COMMAND;
// eslint-disable-next-line github/no-then
connection.command(ns('admin.$cmd'), { [commandName]: 1 }, undefined).then(
() => this.measureAndReschedule(),
() => this.measureAndReschedule(start),
() => {
this.connection?.destroy();
this.connection = undefined;
Expand Down