@@ -795,27 +795,30 @@ func (s *Server) check() (description.Server, error) {
795795 var duration time.Duration
796796
797797 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.
798801 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"
801803 if s .conn != nil {
802- s . publishServerHeartbeatStartedEvent ( s . conn .ID (), false )
804+ connID = s . conn .ID ()
803805 }
806+ s .publishServerHeartbeatStartedEvent (connID , false )
804807 // Create a new connection and add it's handshake RTT as a sample.
805808 err = s .setupHeartbeatConnection ()
806809 duration = time .Since (start )
810+ connID = "0"
811+ if s .conn != nil {
812+ connID = s .conn .ID ()
813+ }
807814 if err == nil {
808815 // Use the description from the connection handshake as the value for this check.
809816 s .rttMonitor .addSample (s .conn .helloRTT )
810817 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 )
814819 } else {
815820 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 )
819822 }
820823 } else {
821824 // An existing connection is being used. Use the server description properties to execute the right heartbeat.
0 commit comments