From 2a248b171c1196b9f7e30ace9ff792f51e3a70b6 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Wed, 19 Feb 2025 13:13:55 +1100 Subject: [PATCH] fix(vpn/tunnel): cancel updater ticks on tunnel stop (#16598) Closes https://github.com/coder/coder-desktop-macos/issues/51. --- vpn/tunnel.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vpn/tunnel.go b/vpn/tunnel.go index 002963ae02..e40732ae10 100644 --- a/vpn/tunnel.go +++ b/vpn/tunnel.go @@ -71,6 +71,7 @@ func NewTunnel( if err != nil { return nil, err } + uCtx, uCancel := context.WithCancel(ctx) t := &Tunnel{ //nolint:govet // safe to copy the locks here because we haven't started the speaker speaker: *(s), @@ -80,7 +81,8 @@ func NewTunnel( requestLoopDone: make(chan struct{}), client: client, updater: updater{ - ctx: ctx, + ctx: uCtx, + cancel: uCancel, netLoopDone: make(chan struct{}), uSendCh: s.sendCh, agents: map[uuid.UUID]tailnet.Agent{}, @@ -317,6 +319,7 @@ func sinkEntryToPb(e slog.SinkEntry) *Log { // updates to the manager. type updater struct { ctx context.Context + cancel context.CancelFunc netLoopDone chan struct{} mu sync.Mutex @@ -480,6 +483,7 @@ func (u *updater) stop() error { } err := u.conn.Close() u.conn = nil + u.cancel() return err }