Skip to content

Commit a354fd8

Browse files
author
Divjot Arora
committed
shane's comments
1 parent 4784649 commit a354fd8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

x/mongo/driver/topology/server.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,11 @@ func (s *Server) ProcessError(err error, conn driver.Connection) {
381381
}
382382

383383
// For a non-timeout network error, we clear the pool, set the description to Unknown, and cancel the in-progress
384-
// monitoring check.
385-
s.cancelCheck()
384+
// monitoring check. The check is cancelled last to avoid a post-cancellation reconnect racing with
385+
// updateDescription.
386386
s.updateDescription(description.NewServerFromError(s.address, err))
387387
s.pool.clear()
388+
s.cancelCheck()
388389
}
389390

390391
// update handles performing heartbeats and updating any subscribers of the
@@ -581,9 +582,9 @@ func (s *Server) cancelCheck() {
581582
return
582583
}
583584

584-
// If the connection exists, we need to wait for it to be connected. We can ignore the error from conn.wait(). If
585-
// the connection wasn't successfully opened, its state was set back to disconnected, so calling conn.close() will
586-
// be a noop.
585+
// If the connection exists, we need to wait for it to be connected conn.connect() and conn.close() cannot be called
586+
// concurrently. We can ignore the error from conn.wait(). If the connection wasn't successfully opened, its state
587+
// was set back to disconnected, so calling conn.close() will be a noop.
587588
conn.closeConnectContext()
588589
_ = conn.wait()
589590
_ = conn.close()

0 commit comments

Comments
 (0)