fix(vpn/tunnel): cancel updater ticks on tunnel stop (#16598)

Closes https://github.com/coder/coder-desktop-macos/issues/51.
This commit is contained in:
Ethan
2025-02-19 13:13:55 +11:00
committed by GitHub
parent 06b2186fe8
commit 2a248b171c

View File

@ -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
}