diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2021-04-21 14:17:21 -0700 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2021-04-21 14:40:05 -0700 |
| commit | 664f490bf1fcb55417b9e0b1eca8d46fb6272cd5 (patch) | |
| tree | e5ad0ecf2bbb4c72bdff9010bbe69d7747c30352 /control/controlclient/direct.go | |
| parent | 2f17a34242bd73036a3c55a02caf9ad07f60fb45 (diff) | |
| download | tailscale-bradfitz/sleep.tar.xz tailscale-bradfitz/sleep.zip | |
control/controlclient, tailcfg: add Debug.SleepSeconds (mapver 19)bradfitz/sleep
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'control/controlclient/direct.go')
| -rw-r--r-- | control/controlclient/direct.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 96bd268b4..726d86fd7 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -795,6 +795,45 @@ func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, cb func(*netm } setControlAtomic(&controlUseDERPRoute, resp.Debug.DERPRoute) setControlAtomic(&controlTrimWGConfig, resp.Debug.TrimWGConfig) + if sleep := time.Duration(resp.Debug.SleepSeconds * float64(time.Second)); sleep > 0 { + const maxSleep = 5 * time.Minute + // SleepFor sleeps for d, but keeps the poll timeout from + // firing while we're sleeeping. + sleepFor := func(d time.Duration) { + ticker := time.NewTicker(pollTimeout / 2) + defer ticker.Stop() + timer := time.NewTimer(d) + defer timer.Stop() + for { + select { + case <-ctx.Done(): + return + case <-timer.C: + return + case <-ticker.C: + select { + case timeoutReset <- struct{}{}: + case <-timer.C: + return + case <-ctx.Done(): + return + } + } + } + } + if sleep > maxSleep { + c.logf("sleeping for %v, capped from server-requested %v ...", maxSleep, sleep) + sleepFor(maxSleep) + } else { + c.logf("sleeping for server-requested %v ...", sleep) + sleepFor(sleep) + } + select { + default: + case <-ctx.Done(): + return ctx.Err() + } + } } nm := sess.netmapForResponse(&resp) |
