Skip to content

Commit

Permalink
GODRIVER-3107 [master] Fix leaking rttMonitor.runHellos() routine. (#…
Browse files Browse the repository at this point in the history
…1611)

Co-authored-by: Qingyang Hu <103950869+qingyang-hu@users.noreply.github.com>
  • Loading branch information
blink1073 and qingyang-hu committed Apr 22, 2024
1 parent 70403cd commit 27aacc5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 0 additions & 6 deletions x/mongo/driver/topology/rtt_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type rttMonitor struct {
cfg *rttConfig
ctx context.Context
cancelFn context.CancelFunc
started bool
}

var _ driver.RTTMonitor = &rttMonitor{}
Expand All @@ -78,7 +77,6 @@ func (r *rttMonitor) connect() {
r.connMu.Lock()
defer r.connMu.Unlock()

r.started = true
r.closeWg.Add(1)

go func() {
Expand All @@ -92,10 +90,6 @@ func (r *rttMonitor) disconnect() {
r.connMu.Lock()
defer r.connMu.Unlock()

if !r.started {
return
}

r.cancelFn()

// Wait for the existing connection to complete.
Expand Down
7 changes: 4 additions & 3 deletions x/mongo/driver/topology/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Server struct {

processErrorLock sync.Mutex
rttMonitor *rttMonitor
monitorOnce sync.Once
}

// updateTopologyCallback is a callback used to create a server that should be called when the parent Topology instance
Expand Down Expand Up @@ -285,10 +286,10 @@ func (s *Server) Disconnect(ctx context.Context) error {
close(s.done)
s.cancelCheck()

s.rttMonitor.disconnect()
s.pool.close(ctx)

s.closewg.Wait()
s.rttMonitor.disconnect()
atomic.StoreInt64(&s.state, serverDisconnected)

return nil
Expand Down Expand Up @@ -666,8 +667,8 @@ func (s *Server) update() {
transitionedFromNetworkError := desc.LastError != nil && unwrapConnectionError(desc.LastError) != nil &&
previousDescription.Kind != description.Unknown

if isStreamingEnabled(s) && isStreamable(s) && !s.rttMonitor.started {
s.rttMonitor.connect()
if isStreamingEnabled(s) && isStreamable(s) {
s.monitorOnce.Do(s.rttMonitor.connect)
}

if isStreamable(s) && (serverSupportsStreaming || connectionIsStreaming) || transitionedFromNetworkError {
Expand Down

0 comments on commit 27aacc5

Please sign in to comment.