wgengine/magicsock: make time.Sleep in runDerpReader respect cancellation.

Before this patch, the 250ms sleep would not be interrupted by context cancellation,
which would result in the goroutine sometimes lingering in tests (100ms grace period).

Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
pull/563/head
Dmytro Shynkevych 4 years ago
parent 891898525c
commit 380ee76d00
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23

@ -1134,7 +1134,12 @@ func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netaddr.IPPort, d
}
c.ReSTUN("derp-close")
c.logf("magicsock: [%p] derp.Recv(derp-%d): %v", dc, regionID, err)
time.Sleep(250 * time.Millisecond)
select {
case <-ctx.Done():
return
// Avoid excessive spinning.
case <-time.Sleep(250 * time.Millisecond):
}
continue
}
switch m := msg.(type) {

Loading…
Cancel
Save