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-5785): do not deserialize heartbeat events with promoteBuffers set to true #4063

Closed
wants to merge 7 commits into from

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Apr 1, 2024

Description

What is changing?

This PR sets promoteBuffers to false for the monitor class. This change is almost entirely invisible to users because monitors are not publicly exposed.

Server heartbeat events and log message are impacted by this change, but we don't currently include the types of each field in the server's heartbeat as a part of our semver-supported API.

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Setting promoteBuffers: true increases the size of an EJSON.stringified heartbeat event, increasing the likelihood that log messages are truncated.

Double check the following

  • Ran npm run check:lint script
  • 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

@baileympearson baileympearson changed the title chore(NODE-5785): set promoteBuffers to false when monitoring fix(NODE-5785): do not deserialize heartbeat events with promoteBuffers set to true Apr 2, 2024
@baileympearson baileympearson marked this pull request as ready for review April 2, 2024 22:22
@W-A-James W-A-James self-assigned this Apr 3, 2024
@W-A-James W-A-James added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 3, 2024
Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one question

Comment on lines +38 to +40
requires: {
topology: ['replicaset', 'sharded']
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to run these on standalone as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The $clusterTime field isn't present on heartbeats from standalone servers

@W-A-James W-A-James added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Apr 3, 2024

await client.connect();
// give the driver a chance to connect to all servers and collect some heartbeats
await setTimeout(100);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but just a knowledge question, why is 100ms a sufficient time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we connect, we send initial hello (heartbeat) messages to each server and collect the responses. Since the test is running directly alongside the server, we're expecting the network latency to be very low ~10 ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also because you might notice this sleep is after the awaited connect. Connect will (by default) resolve when the driver finds a primary. That means that connect can resolve before connecting to secondaries, arbiters or other servers.

@nbbeeken
Copy link
Contributor

nbbeeken commented Apr 3, 2024

What is the public-facing fix here?

@baileympearson
Copy link
Contributor Author

What is the public-facing fix here?

@nbbeeken server heartbeat events I guess. Are you thinking this is a "refactor" instead?

@nbbeeken
Copy link
Contributor

nbbeeken commented Apr 3, 2024

Oh I see, ServerHeartbeatSucceededEvent's reply will now be different. Is this a breaking change? While reply is server version/topology dependent, this change is caused by a client-side hardcoded setting that is not otherwise configurable.

@baileympearson
Copy link
Contributor Author

Oh I see, ServerHeartbeatSucceededEvent's reply will now be different. Is this a breaking change? While reply is server version/topology dependent, this change is caused by a client-side hardcoded setting that is not otherwise configurable.

My thought is no - because we type the reply as a Document. I interpret that to mean that the contents of the reply are not guaranteed to be stable (in addition to the fact that reply varies based on topology and server version).

@nbbeeken
Copy link
Contributor

nbbeeken commented Apr 3, 2024

I mentioned the fact that it changes with server version/topology because I think that it makes sense that is the only way reply might change. There's server documentation for how commands respond for each of those cases. This change is exclusively client-side and there's no documentation. A lot of our APIs return Document but I do not think we can make intentional changes to the shape of the return value because of that.

@@ -135,7 +135,7 @@ export class Monitor extends TypedEventEmitter<MonitorEvents> {
useBigInt64: false,
promoteLongs: true,
promoteValues: true,
promoteBuffers: true
promoteBuffers: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving a comment for viz, discussing public API concerns on slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
4 participants