@@ -563,8 +563,8 @@ func (u *updater) stop() error {
563
563
return nil
564
564
}
565
565
err := u .conn .Close ()
566
- u .conn = nil
567
566
u .cancel ()
567
+ u .conn = nil
568
568
return err
569
569
}
570
570
@@ -630,6 +630,13 @@ func (u *updater) recordLatency() {
630
630
u .logger .Warn (u .ctx ,"failed to ping agent" ,slog .F ("agent_id" ,agentID ),slog .Error (err ))
631
631
return
632
632
}
633
+
634
+ u .mu .Lock ()
635
+ defer u .mu .Unlock ()
636
+ if u .conn == nil {
637
+ u .logger .Debug (u .ctx ,"ignoring ping result as connection is closed" ,slog .F ("agent_id" ,agentID ))
638
+ return
639
+ }
633
640
node := u .conn .Node ()
634
641
derpMap := u .conn .DERPMap ()
635
642
derpLatencies := tailnet .ExtractDERPLatency (node ,derpMap )
@@ -640,8 +647,6 @@ func (u *updater) recordLatency() {
640
647
}else {
641
648
u .logger .Debug (u .ctx ,"preferred DERP not found in DERP latency map" ,slog .F ("preferred_derp" ,preferredDerp ))
642
649
}
643
- u .mu .Lock ()
644
- defer u .mu .Unlock ()
645
650
if agent ,ok := u .agents [agentID ];ok {
646
651
agent .lastPing = & lastPing {
647
652
pingDur :pingDur ,