From 60e5761d608c89065f98de460bd1594f954864a5 Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Thu, 13 Jul 2023 20:45:12 -0700 Subject: [PATCH] control/controlclient: reset backoff in mapRoutine on netmap recv We were never resetting the backoff in streaming mapResponses. The call to `PollNetMap` always returns with an error. Changing that contract is harder, so manually reset backoff when a netmap is received. Updates tailscale/corp#12894 Signed-off-by: Maisem Ali --- control/controlclient/auto.go | 2 ++ control/controlclient/direct.go | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/control/controlclient/auto.go b/control/controlclient/auto.go index dab37a510..a27e9e2fa 100644 --- a/control/controlclient/auto.go +++ b/control/controlclient/auto.go @@ -551,6 +551,8 @@ func (c *Auto) mapRoutine() { if stillAuthed { c.sendStatus("mapRoutine-got-netmap", nil, "", nm) } + // Reset the backoff timer if we got a netmap. + bo.BackOff(ctx, nil) }) health.SetInPollNetMap(false) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 006f2614a..ffc0467f7 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -770,6 +770,8 @@ func (c *Direct) SetEndpoints(endpoints []tailcfg.Endpoint) (changed bool) { // PollNetMap makes a /map request to download the network map, calling cb with // each new netmap. +// It always returns a non-nil error describing the reason for the failure +// or why the request ended. func (c *Direct) PollNetMap(ctx context.Context, cb func(*netmap.NetworkMap)) error { return c.sendMapRequest(ctx, -1, false, cb) } @@ -798,7 +800,12 @@ func (c *Direct) SendLiteMapUpdate(ctx context.Context) error { // every minute. const pollTimeout = 120 * time.Second -// cb nil means to omit peers. +// sendMapRequest makes a /map request to download the network map, calling cb with +// each new netmap. If maxPolls is -1, it will poll forever and only returns if +// the context expires or the server returns an error/closes the connection and as +// such always returns a non-nil error. +// +// If cb is nil, OmitPeers will be set to true. func (c *Direct) sendMapRequest(ctx context.Context, maxPolls int, readOnly bool, cb func(*netmap.NetworkMap)) error { metricMapRequests.Add(1) metricMapRequestsActive.Add(1)