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-3107 Fix leaking rttMonitor.runHellos() routine. #1587

Merged
merged 3 commits into from
Apr 22, 2024

Conversation

qingyang-hu
Copy link
Collaborator

GODRIVER-3107

Summary

Fix the leaky rttMonitor.runHellos() routine when a disconnect occurs before a connection takes place.

Background & Motivation

There is a chance that rttMonitor.disconnect() is called before rttMonitor.connect() as described in PR #1376. In that case, the condition in disconnect() triggers a shortcut return which makes the runHellos() routine impossible to be closed.

@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Mar 29, 2024
Copy link
Contributor

API Change Report

No changes found!

s.pool.close(ctx)

s.closewg.Wait()
s.rttMonitor.disconnect()
Copy link
Collaborator Author

@qingyang-hu qingyang-hu Mar 29, 2024

Choose a reason for hiding this comment

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

It does not cause any actual impact whether or not this line is moved. I put it here as a "fail-safe" that disconnects after the update() exits, so rttMonitor.connect() is more likely to be called beforehand.

@qingyang-hu qingyang-hu marked this pull request as ready for review March 29, 2024 20:46
@qingyang-hu qingyang-hu added priority-2-medium Medium Priority PR for Review and removed priority-3-low Low Priority PR for Review labels Apr 1, 2024
@@ -125,6 +125,7 @@ type Server struct {

processErrorLock sync.Mutex
rttMonitor *rttMonitor
monitorOnce *sync.Once
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since Server is always passed as a pointer, this sync.Once can be a non-pointer type (like sync.Mutex above). If it is ever copied, the go vet linter will cause an error.

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 9648fe1 into mongodb:v1 Apr 22, 2024
28 of 33 checks passed
blink1073 pushed a commit to blink1073/mongo-go-driver that referenced this pull request Apr 22, 2024
matthewdale pushed a commit to matthewdale/mongo-go-driver that referenced this pull request Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-2-medium Medium Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants