Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -56,7 +56,6 @@ type rttMonitor struct {
cfg *rttConfig
ctx context.Context
cancelFn context.CancelFunc
started bool
}

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

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

go func() {
Expand All @@ -97,10 +95,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()
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.

atomic.StoreInt64(&s.state, serverDisconnected)

return nil
Expand Down Expand Up @@ -661,8 +662,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) || connectionIsStreaming || transitionedFromNetworkError {
Expand Down