Skip to content

Commit 91f8009

Browse files
committed
lock for conn read
1 parent a472f56 commit 91f8009

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

vpn/tunnel.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ func (u *updater) stop() error {
563563
return nil
564564
}
565565
err := u.conn.Close()
566-
u.conn = nil
567566
u.cancel()
567+
u.conn = nil
568568
return err
569569
}
570570

@@ -630,6 +630,13 @@ func (u *updater) recordLatency() {
630630
u.logger.Warn(u.ctx, "failed to ping agent", slog.F("agent_id", agentID), slog.Error(err))
631631
return
632632
}
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+
}
633640
node := u.conn.Node()
634641
derpMap := u.conn.DERPMap()
635642
derpLatencies := tailnet.ExtractDERPLatency(node, derpMap)
@@ -640,8 +647,6 @@ func (u *updater) recordLatency() {
640647
} else {
641648
u.logger.Debug(u.ctx, "preferred DERP not found in DERP latency map", slog.F("preferred_derp", preferredDerp))
642649
}
643-
u.mu.Lock()
644-
defer u.mu.Unlock()
645650
if agent, ok := u.agents[agentID]; ok {
646651
agent.lastPing = &lastPing{
647652
pingDur: pingDur,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy