Skip to content

Commit 9648fe1

Browse files
authored
GODRIVER-3107 Fix leaking rttMonitor.runHellos() routine. (#1587)
1 parent b1cd906 commit 9648fe1

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

x/mongo/driver/topology/rtt_monitor.go

-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type rttMonitor struct {
5656
cfg *rttConfig
5757
ctx context.Context
5858
cancelFn context.CancelFunc
59-
started bool
6059
}
6160

6261
var _ driver.RTTMonitor = &rttMonitor{}
@@ -83,7 +82,6 @@ func (r *rttMonitor) connect() {
8382
r.connMu.Lock()
8483
defer r.connMu.Unlock()
8584

86-
r.started = true
8785
r.closeWg.Add(1)
8886

8987
go func() {
@@ -97,10 +95,6 @@ func (r *rttMonitor) disconnect() {
9795
r.connMu.Lock()
9896
defer r.connMu.Unlock()
9997

100-
if !r.started {
101-
return
102-
}
103-
10498
r.cancelFn()
10599

106100
// Wait for the existing connection to complete.

x/mongo/driver/topology/server.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type Server struct {
125125

126126
processErrorLock sync.Mutex
127127
rttMonitor *rttMonitor
128+
monitorOnce sync.Once
128129
}
129130

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

288-
s.rttMonitor.disconnect()
289289
s.pool.close(ctx)
290290

291291
s.closewg.Wait()
292+
s.rttMonitor.disconnect()
292293
atomic.StoreInt64(&s.state, serverDisconnected)
293294

294295
return nil
@@ -661,8 +662,8 @@ func (s *Server) update() {
661662
transitionedFromNetworkError := desc.LastError != nil && unwrapConnectionError(desc.LastError) != nil &&
662663
previousDescription.Kind != description.Unknown
663664

664-
if isStreamingEnabled(s) && isStreamable(s) && !s.rttMonitor.started {
665-
s.rttMonitor.connect()
665+
if isStreamingEnabled(s) && isStreamable(s) {
666+
s.monitorOnce.Do(s.rttMonitor.connect)
666667
}
667668

668669
if isStreamable(s) || connectionIsStreaming || transitionedFromNetworkError {

0 commit comments

Comments
 (0)