@@ -760,27 +760,30 @@ func (s *Server) check() (description.Server, error) {
760
760
var duration time.Duration
761
761
762
762
start := time .Now ()
763
+
764
+ // Create a new connection if this is the first check, the connection was closed after an error during the previous
765
+ // check, or the previous check was cancelled.
763
766
if s .conn == nil || s .conn .closed () || s .checkWasCancelled () {
764
- // Create a new connection if this is the first check, the connection was closed after an error during the previous
765
- // check, or the previous check was cancelled.
767
+ connID := "0"
766
768
if s .conn != nil {
767
- s . publishServerHeartbeatStartedEvent ( s . conn .ID (), false )
769
+ connID = s . conn .ID ()
768
770
}
771
+ s .publishServerHeartbeatStartedEvent (connID , false )
769
772
// Create a new connection and add it's handshake RTT as a sample.
770
773
err = s .setupHeartbeatConnection ()
771
774
duration = time .Since (start )
775
+ connID = "0"
776
+ if s .conn != nil {
777
+ connID = s .conn .ID ()
778
+ }
772
779
if err == nil {
773
780
// Use the description from the connection handshake as the value for this check.
774
781
s .rttMonitor .addSample (s .conn .helloRTT )
775
782
descPtr = & s .conn .desc
776
- if s .conn != nil {
777
- s .publishServerHeartbeatSucceededEvent (s .conn .ID (), duration , s .conn .desc , false )
778
- }
783
+ s .publishServerHeartbeatSucceededEvent (connID , duration , s .conn .desc , false )
779
784
} else {
780
785
err = unwrapConnectionError (err )
781
- if s .conn != nil {
782
- s .publishServerHeartbeatFailedEvent (s .conn .ID (), duration , err , false )
783
- }
786
+ s .publishServerHeartbeatFailedEvent (connID , duration , err , false )
784
787
}
785
788
} else {
786
789
// An existing connection is being used. Use the server description properties to execute the right heartbeat.
0 commit comments