From 54f58d114332c1075133061764265d30455f6348 Mon Sep 17 00:00:00 2001 From: Adrian Dewhurst Date: Mon, 15 Jul 2024 13:28:42 -0400 Subject: [PATCH] ipn/ipnlocal: add comment explaining auto exit node migration Updates tailscale/corp#19681 Change-Id: I6d396780b058ff0fbea0e9e53100f04ef3b76339 Signed-off-by: Adrian Dewhurst --- ipn/ipnlocal/local.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index e22c20318..4fb74b75c 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -4884,6 +4884,27 @@ func (b *LocalBackend) setNetInfo(ni *tailcfg.NetInfo) { cc := b.cc var refresh bool if b.MagicConn().DERPs() > 0 || testenv.InTest() { + // When b.refreshAutoExitNode is set, we recently observed a link change + // that indicates we have switched networks. After switching networks, + // the previously selected automatic exit node is no longer as likely + // to be a good choice and connectivity will already be broken due to + // the network switch. Therefore, it is a good time to switch to a new + // exit node because the network is already disrupted. + // + // Unfortunately, at the time of the link change, no information is + // known about the new network's latency or location, so the necessary + // details are not available to make a new choice. Instead, it sets + // b.refreshAutoExitNode to signal that a new decision should be made + // when we have an updated netcheck report. ni is that updated report. + // + // However, during testing we observed that often the first ni is + // inconclusive because it was running during the link change or the + // link was otherwise not stable yet. b.MagicConn().updateEndpoints() + // can detect when the netcheck failed and trigger a rebind, but the + // required information is not available here, and moderate additional + // plumbing is required to pass that in. Instead, checking for an active + // DERP link offers an easy approximation. We will continue to refine + // this over time. refresh = b.refreshAutoExitNode b.refreshAutoExitNode = false }