Skip to content

Commit 117560f

Browse files
committed
GODRIVER-2577 Fix the logic of starting a heartbeat.
1 parent 486ba91 commit 117560f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

x/mongo/driver/topology/server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,12 @@ func (s *Server) check() (description.Server, error) {
735735
previousDescription := s.Description()
736736
streamable := previousDescription.TopologyVersion != nil
737737

738-
isNilConn := s.conn == nil
739-
if !isNilConn {
738+
if s.conn != nil {
740739
s.publishServerHeartbeatStartedEvent(s.conn.ID(), s.conn.getCurrentlyStreaming() || streamable)
741740
}
742741
// Create a new connection if this is the first check, the connection was closed after an error during the previous
743742
// check, or the previous check was cancelled.
744-
if isNilConn || s.conn.closed() || s.checkWasCancelled() {
743+
if s.conn == nil || s.conn.closed() || s.checkWasCancelled() {
745744
// Create a new connection and add it's handshake RTT as a sample.
746745
err = s.setupHeartbeatConnection()
747746
if err == nil {
@@ -751,9 +750,7 @@ func (s *Server) check() (description.Server, error) {
751750
} else {
752751
err = unwrapConnectionError(err)
753752
}
754-
}
755-
756-
if !isNilConn && err == nil {
753+
} else {
757754
// An existing connection is being used. Use the server description properties to execute the right heartbeat.
758755

759756
// Wrap conn in a type that implements driver.StreamerConnection.

0 commit comments

Comments
 (0)