From b847ca85e4a781037ad40407f6714048dc5fcfb9 Mon Sep 17 00:00:00 2001 From: Brendan Creane Date: Thu, 19 Nov 2026 23:17:53 +0000 Subject: [PATCH] ipn/ipnlocal: send the control status Notify from a deferred call The body of setControlClientStatusLocked that applies a status moves to applyControlClientStatusLocked, which sends its one Notify from a defer. An early return can no longer skip the send, and the state machine still runs after the send in the caller. The client-replaced return clears the pending flag explicitly, since that Notify is dropped on purpose. Updates #22206 Signed-off-by: Brendan Creane --- ipn/ipnlocal/local.go | 47 ++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 48857e6ee..9993bdd0e 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1962,6 +1962,26 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c return } + if !b.applyControlClientStatusLocked(c, st) { + return + } + if st.URL != "" { + b.logf("Received auth URL: %.20v...", st.URL) + b.setAuthURLLocked(st.URL) + } + b.stateMachineLocked() + // This is currently (2020-07-28) necessary; conditionally disabling it is fragile! + // This is where netmap information gets propagated to router and magicsock. + b.authReconfigLocked() +} + +// applyControlClientStatusLocked applies a status that carries no error. It +// updates the login state, the prefs, the netmap, and the exit node, sends +// one [ipn.Notify] for everything it changed, and reports whether the caller +// should go on to run the state machine. +// +// b.mu must be held. +func (b *LocalBackend) applyControlClientStatusLocked(c controlclient.Client, st controlclient.Status) (runStateMachine bool) { // Track the number of calls currCall := b.numClientStatusCalls.Add(1) @@ -1994,9 +2014,14 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c } // notify collects the login, prefs, netmap, and exit node changes from - // this status. It is sent once, below, before the state machine runs. + // this status. The deferred send runs on every return. var notify ipn.Notify notifyPending := false // true once notify must be sent + defer func() { + if notifyPending { + b.sendLocked(notify) + } + }() wasBlocked := b.blocked authWasInProgress := b.authURL != "" @@ -2120,7 +2145,8 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c // The Notify built so far is dropped. The replacing path has // already sent its own prefs. b.logf("Ignoring SetControlClientStatus from old client") - return + notifyPending = false + return false } // b.cc is nil for a cached netmap applied by startLocked. if b.cc != nil { @@ -2164,8 +2190,8 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c notify.ErrMessage = &msg notify.Prefs = new(b.pm.CurrentPrefs()) b.addSuggestedExitNodeLocked(¬ify) - b.sendLocked(notify) - return + notifyPending = true + return false } if oldNetMap != nil { diff := st.NetMap.ConciseDiffFrom(oldNetMap) @@ -2249,18 +2275,7 @@ func (b *LocalBackend) setControlClientStatusLocked(c controlclient.Client, st c if b.addSuggestedExitNodeLocked(¬ify) { notifyPending = true } - if notifyPending { - b.sendLocked(notify) - } - - if st.URL != "" { - b.logf("Received auth URL: %.20v...", st.URL) - b.setAuthURLLocked(st.URL) - } - b.stateMachineLocked() - // This is currently (2020-07-28) necessary; conditionally disabling it is fragile! - // This is where netmap information gets propagated to router and magicsock. - b.authReconfigLocked() + return true } // handleNetmapExpiry reruns netmap status handling when a node may have