From a7769cbc33a3eba62bb16fc803b97077c2969d16 Mon Sep 17 00:00:00 2001 From: Fran Bull Date: Wed, 26 Aug 2026 08:51:59 -0700 Subject: [PATCH] feature/conn25: check online when picking connector So that when control notices a node isn't responding and sends that info down in a netmap we will stop picking that node as a connector. This doesn't provide great failover (it takes several minutes) but it's better than not failing over at all. Updates tailscale/corp#47250 Signed-off-by: Fran Bull --- feature/conn25/conn25.go | 9 ++++++--- feature/conn25/conn25_test.go | 23 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/feature/conn25/conn25.go b/feature/conn25/conn25.go index 7bf9a5763d..952cfead8c 100644 --- a/feature/conn25/conn25.go +++ b/feature/conn25/conn25.go @@ -1104,7 +1104,7 @@ func makePeerAPIReq(ctx context.Context, httpClient *http.Client, urlBase string func (e *extension) pickConnectorURLBase(app appctype.Conn25Attr) (tailcfg.NodeView, string) { nb := e.host.NodeBackend() - peers := PickConnector(nb, app) + peers := pickConnector(nb, app) var urlBase string var conn tailcfg.NodeView for _, p := range peers { @@ -1690,14 +1690,17 @@ func sortByPreference(ns []tailcfg.NodeView) { }) } -// PickConnector returns peers the backend knows about that match the app, in order of preference to use as +// pickConnector returns peers the backend knows about that match the app, in order of preference to use as // a connector. -func PickConnector(nb ipnext.NodeBackend, app appctype.Conn25Attr) []tailcfg.NodeView { +func pickConnector(nb ipnext.NodeBackend, app appctype.Conn25Attr) []tailcfg.NodeView { appTagsSet := set.SetOf(app.Connectors) matches := nb.AppendMatchingPeers(nil, func(n tailcfg.NodeView) bool { if !isPeerEligibleConnector(n) { return false } + if !n.Online().Get() { + return false + } for _, t := range n.Tags().All() { if appTagsSet.Contains(t) { return true diff --git a/feature/conn25/conn25_test.go b/feature/conn25/conn25_test.go index 6ccbefd52b..00dd06ee6a 100644 --- a/feature/conn25/conn25_test.go +++ b/feature/conn25/conn25_test.go @@ -1668,6 +1668,7 @@ func TestAddressAssignmentIsHandled(t *testing.T) { Tags: []string{"tag:woo"}, Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(), Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 1: 0xff, 31: 0x01})), + Online: new(true), }).View() ext := &extension{ @@ -2362,12 +2363,14 @@ func TestHandleAddressAssignmentStoresTransitIPs(t *testing.T) { Tags: []string{"tag:woo"}, Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(), Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 31: 0x01})), + Online: new(true), }).View(), (&tailcfg.Node{ ID: tailcfg.NodeID(2), Tags: []string{"tag:hoo"}, Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(), Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 31: 0x02})), + Online: new(true), }).View(), } @@ -3256,6 +3259,16 @@ func TestPickConnector(t *testing.T) { ID: id, Tags: tags, Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(isConnector)}).View(), + Online: new(true), + }).View() + } + + nvWithOnlineSet := func(id tailcfg.NodeID, online bool, tags ...string) tailcfg.NodeView { + return (&tailcfg.Node{ + ID: id, + Tags: tags, + Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(), + Online: new(online), }).View() } @@ -3318,7 +3331,7 @@ func TestPickConnector(t *testing.T) { }, { name: "not-a-connector", - candidates: []tailcfg.NodeView{nvWithConnectorSet(1, false, "tag:example.com"), nv(2, "tag:example")}, + candidates: []tailcfg.NodeView{nvWithConnectorSet(1, false, "tag:example"), nv(2, "tag:example")}, app: exampleApp, want: []tailcfg.NodeView{nv(2, "tag:example")}, }, @@ -3370,9 +3383,15 @@ func TestPickConnector(t *testing.T) { nv(7, "tag:example1", "tag:example"), }, }, + { + name: "not-online", + candidates: []tailcfg.NodeView{nvWithOnlineSet(1, false, "tag:example"), nv(2, "tag:example")}, + app: exampleApp, + want: []tailcfg.NodeView{nv(2, "tag:example")}, + }, } { t.Run(tt.name, func(t *testing.T) { - got := PickConnector(&testNodeBackend{peers: tt.candidates}, tt.app) + got := pickConnector(&testNodeBackend{peers: tt.candidates}, tt.app) if diff := cmp.Diff(tt.want, got); diff != "" { t.Fatalf("PickConnectors (-want, +got):\n%s", diff) }