ipn/ipnlocal,tstest/integration: pause the control client consistently (#19846)
There are two places where tailscaled transitions into a paused state: 1. tailscaled’s controlclient is initially created, 2. tailscale down, or the GUI equivalent, commands it to. This patch unifies the implementation of both scenarios into LocalBackend.shouldPauseControlClientLocked to prevent the implementation from drifting. The flaky tstest/integration.TestNoControlConnWhenDown test exposed this mismatch, but only by accident. This patch also changes TestNode.MustDown so that it runs `tailscale down` and then waits for the testcontrol server to finish handling any associated /machine/map requests. Fixes #19831 Signed-off-by: Simon Law <sfllaw@tailscale.com>
This commit is contained in:
+29
-5
@@ -1037,13 +1037,37 @@ func (b *LocalBackend) pauseOrResumeControlClientLocked() {
|
||||
if b.cc == nil {
|
||||
return
|
||||
}
|
||||
networkUp := b.interfaceState.AnyInterfaceUp()
|
||||
pauseForNetwork := (b.state == ipn.Stopped && b.NetMapNoPeers() != nil) || (!networkUp && !testenv.InTest() && !envknob.AssumeNetworkUp())
|
||||
b.cc.SetPaused(b.shouldPauseControlClientLocked(b.pm.CurrentPrefs()))
|
||||
}
|
||||
|
||||
// shouldPauseControlClientLocked reports whether the control client should be paused:
|
||||
// if the LocalBackend is in Stopped state with a valid NetMap,
|
||||
// if there is no network available,
|
||||
// or if syncing preferences from the control plane has been disabled.
|
||||
//
|
||||
// b.mu must be held.
|
||||
func (b *LocalBackend) shouldPauseControlClientLocked(prefs ipn.PrefsView) bool {
|
||||
syncs.RequiresMutex(&b.mu)
|
||||
|
||||
prefs := b.pm.CurrentPrefs()
|
||||
pauseForSyncPref := prefs.Valid() && prefs.Sync().EqualBool(false)
|
||||
if pauseForSyncPref {
|
||||
return true
|
||||
}
|
||||
|
||||
b.cc.SetPaused(pauseForNetwork || pauseForSyncPref)
|
||||
// If tailscaled is being restarted, but it is supposed to be stopped,
|
||||
// it mustn’t pause until the initial netmap has been loaded.
|
||||
isStopped := b.state == ipn.Stopped && b.NetMapNoPeers() != nil
|
||||
if isStopped {
|
||||
return true
|
||||
}
|
||||
|
||||
networkUp := b.interfaceState.AnyInterfaceUp()
|
||||
pauseForNetwork := !networkUp && !testenv.InTest() && !envknob.AssumeNetworkUp()
|
||||
if pauseForNetwork {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// DisconnectControl shuts down control client. This can be run before node shutdown to force control to consider this ndoe
|
||||
@@ -2961,7 +2985,7 @@ func (b *LocalBackend) startLocked(opts ipn.Options) error {
|
||||
ControlKnobs: b.sys.ControlKnobs(),
|
||||
Shutdown: ccShutdown,
|
||||
Bus: b.sys.Bus.Get(),
|
||||
StartPaused: prefs.Sync().EqualBool(false),
|
||||
StartPaused: b.shouldPauseControlClientLocked(prefs),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user