Skip to content

fix(NODE-7985): keep sampling round-trip time after a failed measurement - #5103

Open
tap1r wants to merge 1 commit into
mongodb:mainfrom
tap1r:fix/rtt-pinger-reschedule
Open

tap1r wants to merge 1 commit into
mongodb:mainfrom
tap1r:fix/rtt-pinger-reschedule

Conversation

@tap1r

@tap1r tap1r commented Nov 3, 2026 •

Copy link
Copy Markdown

Description

Summary of Changes

RTTPinger schedules another round-trip sample after connect fails or the dedicated hello fails. A failed attempt does not replace latestRtt.

Notes for Reviewers

connect() already destroys the socket when the handshake fails, so the connect-failure path only clears the pinger's connection reference and arms the next timer. The command-failure path still destroys the dedicated connection, which is what test/integration/connection-monitoring-and-pooling/rtt_pinger.test.ts asserts. That test was not run here (it needs a MongoDB deployment). The new unit tests cover both failure paths with mongodb-mock and a refused local port.

Jira: NODE-7985

What is the motivation for this change?

One dropped RTT socket made server selection and operation timeouts keep a stale round-trip time for as long as the server kept streaming hellos.

For bug fixes

Current (incorrect) behavior:

After the dedicated RTT connection fails to connect, or its hello fails, no further RTT sample is scheduled. latestRtt stays at the last success. The streaming hello monitor is unaffected.

Expected behavior:

The pinger destroys the failed socket, leaves latestRtt unchanged, and measures again after heartbeatFrequencyMS. A later success updates latestRtt.

How to reproduce:

Create an RTTPinger against a mock that accepts the first hello and destroys the socket on the second. Before this change the pinger stops at two hellos. After it, a third hello is sent and latestRtt is still the value captured from the successful sample at the moment the failed command rejects.

Unit coverage: test/unit/sdam/rtt_pinger.test.ts.

Affected versions:

Present on main. Requires a server that advertises topologyVersion so the driver creates an RTTPinger (streaming monitoring, MongoDB 4.4+). The bug is in the driver, not in a particular server version beyond that.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

RTTPinger.measureRoundTripTime returned after a connect failure or a
hello failure and never armed the next sample. latestRtt then stayed at
the last successful value while streaming heartbeats and client-side
operation timeouts kept using it. The hello monitor itself continued.

Schedule the next sample after heartbeatFrequencyMS on either failure.
Do not store the failed duration as latestRtt. connect() already
destroys the socket it failed to open. The command-failure path still
destroys the dedicated connection before the next sample opens another.
@tap1r
tap1r requested a review from a team as a code owner November 3, 2026 23:56
@tap1r tap1r changed the title fix: keep sampling round-trip time after a failed measurement fix(NODE-7985): keep sampling round-trip time after a failed measurement Nov 4, 2026
@PavelSafronov PavelSafronov added tracked-in-jira Ticket filed in MongoDB's Jira system External Submission PR submitted from outside the team labels Nov 6, 2026
@PavelSafronov

Copy link
Copy Markdown
Contributor

@tap1r, thank you for taking the time to create this PR! This is tracked in NODE-7985. The team is currently at capacity, so we will be reviewing it over the next few quarters as capacity allows.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Submission PR submitted from outside the team tracked-in-jira Ticket filed in MongoDB's Jira system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants