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

GODRIVER-2966 Remove the heartbeat events after a connection is closed / a check is canceled. #1378

Merged
merged 7 commits into from
Oct 3, 2023

Conversation

qingyang-hu
Copy link
Collaborator

GODRIVER-2966

Summary

Remove the heartbeat events when checking on the server after a connection is closed / a check is canceled.

Background & Motivation

@qingyang-hu qingyang-hu marked this pull request as ready for review September 6, 2023 23:05
@qingyang-hu qingyang-hu requested a review from a team as a code owner September 6, 2023 23:05
@qingyang-hu qingyang-hu requested review from matthewdale and prestonvasquez and removed request for a team September 6, 2023 23:05
prestonvasquez
prestonvasquez previously approved these changes Sep 6, 2023
Copy link
Collaborator

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

LGTM! Did you notice any freezing with the lambda update? Which CI tasks would this be tested in?

@qingyang-hu
Copy link
Collaborator Author

Unfortunately, we don't have a CI task to test against the lambda freezing. I can try to add one.

@qingyang-hu qingyang-hu marked this pull request as draft September 7, 2023 20:18
matthewdale
matthewdale previously approved these changes Sep 11, 2023
Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@prestonvasquez
Copy link
Collaborator

prestonvasquez commented Sep 11, 2023

@qingyang-hu Currently there is no clear requirement in the SDAM specifications that requires us to publish heartbeat events when attempting to establish a connection. However, many drivers do this including Python, Node, and Rust.

Go Driver only publishes the "started" event when the connection is not nil. So we don't publish this event on the initial connection, per se. Only when we re-establish connections. The reason we do this comes from PR #1133 , where IIUC it was determined that passing an empty value for the connection ID is not appropriate. There is a Drivers ticket open for this right now, DRIVERS-2677 , where it has been suggested that passing a "0" value for the connectionID is a viable solution in this case since connectionID starts at "1".

I suggest we do three things to resolve this PR:

  1. Remove the if block here: https://github.com/mongodb/mongo-go-driver/blob/master/x/mongo/driver/topology/server.go#L801 , but leave the publication. When the connection ID is unknown, then publish that values as "0".

  2. Remove this entire block: https://github.com/mongodb/mongo-go-driver/blob/master/x/mongo/driver/topology/server.go#L811-L813 . IIUC, it is a duplicate of this publication: https://github.com/mongodb/mongo-go-driver/blob/master/x/mongo/driver/topology/server.go#L865 . Is that correct?

  3. Remove this entire block: https://github.com/mongodb/mongo-go-driver/blob/master/x/mongo/driver/topology/server.go#L816-L818 . IIUC, it is a duplicate of this publication: https://github.com/mongodb/mongo-go-driver/blob/master/x/mongo/driver/topology/server.go#L872 . Is that correct?

CC: @matthewdale , @ShaneHarvey

@qingyang-hu
Copy link
Collaborator Author

I think, instead, we need to remove all publications in the else block L820-L874 including L829 if we plan to publish heartbeat events when attempting to establish a connection.

@prestonvasquez
Copy link
Collaborator

I think, instead, we need to remove all publications in the else block L820-L874 including L829 if we plan to publish heartbeat events when attempting to establish a connection.

The publications in the else block are required by the specification, i.e. before we send a hello command and whether or not the hello failed/succeeded: https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.rst#events-api

@qingyang-hu qingyang-hu marked this pull request as ready for review September 13, 2023 17:59
@prestonvasquez prestonvasquez changed the base branch from master to v1 September 13, 2023 18:06
if s.conn == nil || s.conn.closed() || s.checkWasCancelled() {
// Create a new connection if this is the first check, the connection was closed after an error during the previous
// check, or the previous check was cancelled.
connID := "0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

A connection ID of "0" doesn't match the existing pattern of "<addr>[-<number>]" (see here). Using an empty string seems more correct for when the connection is nil.

}
s.publishServerHeartbeatStartedEvent(connID, false)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should do something similar for the subsequent publishServerHeartbeatSucceededEvent and publishServerHeartbeatFailedEvent so they always get published, even if the conn is nil. That's especially important for the failed event so we can report the error.

prestonvasquez
prestonvasquez previously approved these changes Sep 15, 2023
Copy link
Collaborator

@prestonvasquez prestonvasquez left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@matthewdale matthewdale left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@qingyang-hu qingyang-hu merged commit 4a26e6c into mongodb:v1 Oct 3, 2023
0 of 2 checks passed
blink1073 pushed a commit to blink1073/mongo-go-driver that referenced this pull request Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants