wgengine/magicsock: re-stun every [20,27] sec, not 28

28 is cutting it close, and we think jitter will help some spikes
we're seeing.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/223/head
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent 2c7ddd0828
commit 2d48f92a82

@ -1371,14 +1371,20 @@ func (c *Conn) Close() error {
}
func (c *Conn) periodicReSTUN() {
ticker := time.NewTicker(28 * time.Second) // just under 30s, a likely UDP NAT timeout
defer ticker.Stop()
prand := rand.New(rand.NewSource(time.Now().UnixNano()))
dur := func() time.Duration {
// Just under 30s, a common UDP NAT timeout (Linux at least)
return time.Duration(20+prand.Intn(7)) * time.Second
}
timer := time.NewTimer(dur())
defer timer.Stop()
for {
select {
case <-c.donec():
return
case <-ticker.C:
case <-timer.C:
c.ReSTUN("periodic")
timer.Reset(dur())
}
}
}

Loading…
Cancel
Save