Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/tsutil: add exponential falloff to retries when polling #154

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions internal/tsutil/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func (p *Poller) Run(ctx context.Context) {
if interval < 0 {
interval = 5 * time.Second
}
retry := interval

check := time.NewTicker(interval)
defer check.Stop()
Expand All @@ -70,7 +71,15 @@ func (p *Poller) Run(ctx context.Context) {
return
}
slog.Error("get Tailscale status", "err", err)
continue
select {
case <-ctx.Done():
return
case <-time.After(retry):
if retry < 30*time.Second {
retry *= 2
}
continue
}
}

prefs, err := Prefs(ctx)
Expand All @@ -79,9 +88,19 @@ func (p *Poller) Run(ctx context.Context) {
return
}
slog.Error("get Tailscale prefs", "err", err)
continue
select {
case <-ctx.Done():
return
case <-time.After(retry):
if retry < 30*time.Second {
retry *= 2
}
continue
}
}

retry = interval

var files []apitype.WaitingFile
if status.Self.HasCap(tailcfg.CapabilityFileSharing) {
files, err = WaitingFiles(ctx)
Expand Down
Loading