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>
This commit is contained in:
Dmytro Shynkevych 2020-07-16 10:44:57 -04:00
parent 891898525c
commit 380ee76d00
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23
1 changed files with 6 additions and 1 deletions

View File

@ -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) {