Skip to content

Commit cc21e0b

Browse files
qingyang-hublink1073
authored andcommitted
GODRIVER-3107 Fix leaking rttMonitor.runHellos() routine. (mongodb#1587)
(cherry picked from commit 9648fe1)
1 parent 70403cd commit cc21e0b

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
@@ -54,7 +54,6 @@ type rttMonitor struct {
5454
cfg *rttConfig
5555
ctx context.Context
5656
cancelFn context.CancelFunc
57-
started bool
5857
}
5958

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

81-
r.started = true
8280
r.closeWg.Add(1)
8381

8482
go func() {
@@ -92,10 +90,6 @@ func (r *rttMonitor) disconnect() {
9290
r.connMu.Lock()
9391
defer r.connMu.Unlock()
9492

95-
if !r.started {
96-
return
97-
}
98-
9993
r.cancelFn()
10094

10195
// 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
@@ -666,8 +667,8 @@ func (s *Server) update() {
666667
transitionedFromNetworkError := desc.LastError != nil && unwrapConnectionError(desc.LastError) != nil &&
667668
previousDescription.Kind != description.Unknown
668669

669-
if isStreamingEnabled(s) && isStreamable(s) && !s.rttMonitor.started {
670-
s.rttMonitor.connect()
670+
if isStreamingEnabled(s) && isStreamable(s) {
671+
s.monitorOnce.Do(s.rttMonitor.connect)
671672
}
672673

673674
if isStreamable(s) && (serverSupportsStreaming || connectionIsStreaming) || transitionedFromNetworkError {

0 commit comments

Comments
 (0)