@@ -760,27 +760,30 @@ func (s *Server) check() (description.Server, error) {
760760 var duration time.Duration
761761
762762 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.
763766 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"
766768 if s .conn != nil {
767- s . publishServerHeartbeatStartedEvent ( s . conn .ID (), false )
769+ connID = s . conn .ID ()
768770 }
771+ s .publishServerHeartbeatStartedEvent (connID , false )
769772 // Create a new connection and add it's handshake RTT as a sample.
770773 err = s .setupHeartbeatConnection ()
771774 duration = time .Since (start )
775+ connID = "0"
776+ if s .conn != nil {
777+ connID = s .conn .ID ()
778+ }
772779 if err == nil {
773780 // Use the description from the connection handshake as the value for this check.
774781 s .rttMonitor .addSample (s .conn .helloRTT )
775782 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 )
779784 } else {
780785 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 )
784787 }
785788 } else {
786789 // An existing connection is being used. Use the server description properties to execute the right heartbeat.
0 commit comments