mirror of
https://github.com/tailscale/tailscale.git
synced 2025-03-27 19:43:01 +00:00
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>
This commit is contained in:
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…
x
Reference in New Issue
Block a user