From 87a4c75fd4d9f20dc7bdcaa1d273b74b1d277dbf Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 19 Jun 2022 22:00:22 -0700 Subject: [PATCH] control/controlclient, ipn/ipnlocal: remove Client.SetExpirySooner, fix race Client.SetExpirySooner isn't part of the state machine. Remove it from the Client interface. And fix a use of LocalBackend.cc without acquiring the lock that guards that field. Signed-off-by: Brad Fitzpatrick --- control/controlclient/client.go | 4 ---- ipn/ipnlocal/local.go | 8 +++++++- ipn/ipnlocal/state_test.go | 6 ------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/control/controlclient/client.go b/control/controlclient/client.go index aac8bf468..75cf5dc61 100644 --- a/control/controlclient/client.go +++ b/control/controlclient/client.go @@ -11,7 +11,6 @@ package controlclient import ( "context" - "time" "tailscale.com/tailcfg" ) @@ -43,9 +42,6 @@ type Client interface { // Logout starts a synchronous logout process. It doesn't return // until the logout operation has been completed. Logout(context.Context) error - // SetExpirySooner sets the node's expiry time via the controlclient, - // as long as it's shorter than the current expiry time. - SetExpirySooner(context.Context, time.Time) error // SetPaused pauses or unpauses the controlclient activity as much // as possible, without losing its internal state, to minimize // unnecessary network activity. diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index fab967a14..6b98978df 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -3369,7 +3369,13 @@ func (b *LocalBackend) allowExitNodeDNSProxyToServeName(name string) bool { // If t is in the past, the key is expired immediately. // If t is after the current expiry, an error is returned. func (b *LocalBackend) SetExpirySooner(ctx context.Context, expiry time.Time) error { - return b.cc.SetExpirySooner(ctx, expiry) + b.mu.Lock() + cc := b.ccAuto + b.mu.Unlock() + if cc == nil { + return errors.New("not running") + } + return cc.SetExpirySooner(ctx, expiry) } // exitNodeCanProxyDNS reports the DoH base URL ("http://foo/dns-query") without query parameters diff --git a/ipn/ipnlocal/state_test.go b/ipn/ipnlocal/state_test.go index f7dfdebe5..d89c50e1e 100644 --- a/ipn/ipnlocal/state_test.go +++ b/ipn/ipnlocal/state_test.go @@ -220,12 +220,6 @@ func (cc *mockControl) Logout(ctx context.Context) error { return nil } -func (cc *mockControl) SetExpirySooner(context.Context, time.Time) error { - cc.logf("SetExpirySooner") - cc.called("SetExpirySooner") - return nil -} - func (cc *mockControl) SetPaused(paused bool) { cc.logf("SetPaused=%v", paused) if paused {