control/controlclient,health: report login errors as impacting connectivity

authRoutine reported login attempts canceled by a pause, shutdown or
new login, such as when LocalBackend is restarting, to the health
tracker. A cancelation is either irrelevant, or it replaces an earlier
error and masks a real issue. Don't report errors once the attempt's
context is done, as is already the case for status updates.

login-state is then unhealthy only when logging in to the control plane
fails, so mark it as impacting connectivity. Among other things, that
lets it trigger captive portal detection.

Updates #12991
Updates #20078
Updates #18116
Updates #13378
Updates #1634
Updates tailscale/corp#27985
Updates #12701
Updates #14126

Signed-off-by: Nick Khyl <[email protected]>
This commit is contained in:
Nick Khyl authored and Nick Khyl committed 2026-11-30 18:09:32 -08:00
1 parent 3696f58e46
commit 00a8cd1ef2
3 files changed
+62 -3

No files matched your search

+2 -2
View File
@@ -334,9 +334,10 @@ func (c *Auto) authRoutine() {
report := func(err error, msg string) {
c.logf("[v1] %s: %v", msg, err)
// don't send status updates for context errors,
// don't report context errors,
// since context cancelation is always on purpose.
if ctx.Err() == nil {
c.direct.health.SetAuthRoutineInError(err)
c.sendStatus("authRoutine-report", err, "", nil)
}
}
@@ -364,7 +365,6 @@ func (c *Auto) authRoutine() {
f = "TryLogin"
}
if err != nil {
c.direct.health.SetAuthRoutineInError(err)
report(err, f)
if rle, ok := errors.AsType[*rateLimitError](err); ok {
c.waitRetryAfter(ctx, "authRoutine", rle)
+58
View File
@@ -5,13 +5,17 @@ package controlclient
import (
"context"
"errors"
"sync"
"testing"
"testing/synctest"
"time"
"tailscale.com/health"
"tailscale.com/tailcfg"
"tailscale.com/tstime"
"tailscale.com/types/key"
"tailscale.com/util/eventbus/eventbustest"
)
func TestMapRoutineBackoffCanBePaused(t *testing.T) {
@@ -171,3 +175,57 @@ func TestWaitRetryAfter(t *testing.T) {
})
}
}
// TestAuthRoutineCanceledLoginNotReportedToHealth verifies that a login
// attempt that fails after it was canceled, such as when the client is
// paused, is not reported as a login error.
func TestAuthRoutineCanceledLoginNotReportedToHealth(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
ht := health.NewTracker(eventbustest.NewBus(t))
ht.SetIPNState("Starting", true)
// Each login attempt blocks until it receives its result.
loginErr := make(chan error)
ctx, cancel := context.WithCancel(t.Context())
c := &Auto{
logf: t.Logf,
direct: &Direct{
logf: t.Logf,
health: ht,
hostinfo: new(tailcfg.Hostinfo),
getMachinePrivKey: func() (key.MachinePrivate, error) {
return key.MachinePrivate{}, <-loginErr
},
},
loginGoal: &LoginGoal{},
authCtx: ctx,
authCancel: cancel,
authDone: make(chan struct{}),
}
defer func() {
c.mu.Lock()
c.closed = true
c.cancelAuthCtxLocked()
c.mu.Unlock()
close(loginErr)
<-c.authDone
}()
go c.authRoutine()
synctest.Wait()
c.mu.Lock()
c.cancelAuthCtxLocked()
c.mu.Unlock()
loginErr <- errors.New("canceled attempt")
synctest.Wait()
if ht.IsUnhealthy(health.LoginStateWarnable) {
t.Error("canceled login attempt was reported to health")
}
loginErr <- errors.New("failed attempt")
synctest.Wait()
if !ht.IsUnhealthy(health.LoginStateWarnable) {
t.Error("failed login attempt was not reported to health")
}
})
}
+2 -1
View File
@@ -115,7 +115,8 @@ var LoginStateWarnable = condRegister(func() *Warnable {
return "You are logged out."
}
},
DependsOn: []*Warnable{IPNStateWarnable},
DependsOn: []*Warnable{IPNStateWarnable},
ImpactsConnectivity: true,
}
})