wgengine/magicsock: always set home DERP if no control conn

The logic we added in #11378 would prevent selecting a home DERP if we
have no control connection.

Updates tailscale/corp#18095

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I44bb6ac4393989444e4961b8cfa27dc149a33c6e
This commit is contained in:
Andrew Dunham
2024-06-25 22:23:19 -04:00
parent a475c435ec
commit 8161024176
2 changed files with 28 additions and 2 deletions

View File

@@ -158,6 +158,10 @@ func (c *Conn) maybeSetNearestDERP(report *netcheck.Report) (preferredDERP int)
//
// For tests, always assume we're connected to control unless we're
// explicitly testing this behaviour.
//
// Despite the above behaviour, ensure that we set the nearest DERP if
// we don't currently have one set; any DERP server is better than
// none, even if not connected to control.
var connectedToControl bool
if testenv.InTest() && !checkControlHealthDuringNearestDERPInTests {
connectedToControl = true
@@ -166,8 +170,15 @@ func (c *Conn) maybeSetNearestDERP(report *netcheck.Report) (preferredDERP int)
}
if !connectedToControl {
c.mu.Lock()
defer c.mu.Unlock()
return c.myDerp
myDerp := c.myDerp
c.mu.Unlock()
if myDerp != 0 {
return myDerp
}
// Intentionally fall through; we don't have a current DERP, so
// as mentioned above selecting one even if not connected is
// strictly better than doing nothing.
}
preferredDERP = report.PreferredDERP