@@ -795,27 +795,30 @@ func (s *Server) check() (description.Server, error) {
795
795
var duration time.Duration
796
796
797
797
start := time .Now ()
798
+
799
+ // Create a new connection if this is the first check, the connection was closed after an error during the previous
800
+ // check, or the previous check was cancelled.
798
801
if s .conn == nil || s .conn .closed () || s .checkWasCancelled () {
799
- // Create a new connection if this is the first check, the connection was closed after an error during the previous
800
- // check, or the previous check was cancelled.
802
+ connID := "0"
801
803
if s .conn != nil {
802
- s . publishServerHeartbeatStartedEvent ( s . conn .ID (), false )
804
+ connID = s . conn .ID ()
803
805
}
806
+ s .publishServerHeartbeatStartedEvent (connID , false )
804
807
// Create a new connection and add it's handshake RTT as a sample.
805
808
err = s .setupHeartbeatConnection ()
806
809
duration = time .Since (start )
810
+ connID = "0"
811
+ if s .conn != nil {
812
+ connID = s .conn .ID ()
813
+ }
807
814
if err == nil {
808
815
// Use the description from the connection handshake as the value for this check.
809
816
s .rttMonitor .addSample (s .conn .helloRTT )
810
817
descPtr = & s .conn .desc
811
- if s .conn != nil {
812
- s .publishServerHeartbeatSucceededEvent (s .conn .ID (), duration , s .conn .desc , false )
813
- }
818
+ s .publishServerHeartbeatSucceededEvent (connID , duration , s .conn .desc , false )
814
819
} else {
815
820
err = unwrapConnectionError (err )
816
- if s .conn != nil {
817
- s .publishServerHeartbeatFailedEvent (s .conn .ID (), duration , err , false )
818
- }
821
+ s .publishServerHeartbeatFailedEvent (connID , duration , err , false )
819
822
}
820
823
} else {
821
824
// An existing connection is being used. Use the server description properties to execute the right heartbeat.
0 commit comments