From edb338f54255bf22b114ca12c434f9e53af487e1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 19 Aug 2021 08:44:39 -0700 Subject: [PATCH] cmd/tailscale: fix sporadic 'context canceled' error on 'up' Fixes #2333 Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/up.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cmd/tailscale/cli/up.go b/cmd/tailscale/cli/up.go index 7587dc342..4ccfc74da 100644 --- a/cmd/tailscale/cli/up.go +++ b/cmd/tailscale/cli/up.go @@ -478,6 +478,13 @@ func runUp(ctx context.Context, args []string) error { } } + // This whole 'up' mechanism is too complicated and results in + // hairy stuff like this select. We're ultimately waiting for + // 'startingOrRunning' to be done, but even in the case where + // it succeeds, other parts may shut down concurrently so we + // need to prioritize reads from 'startingOrRunning' if it's + // readable; its send does happen before the pump mechanism + // shuts down. (Issue 2333) select { case <-startingOrRunning: return nil @@ -489,6 +496,11 @@ func runUp(ctx context.Context, args []string) error { } return pumpCtx.Err() case err := <-pumpErr: + select { + case <-startingOrRunning: + return nil + default: + } return err } }