From 2cdd5b8cc7cc4c3c3b2d8d7b63ad4b5b59c6a014 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 12 Dec 2023 13:10:02 +0000 Subject: [PATCH] Avoid constant rebinding on blocked endpoints --- wgengine/magicsock/magicsock.go | 6 +++--- wgengine/magicsock/magicsock_test.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 06dc19afec897..b0cf73232fbe6 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -548,7 +548,7 @@ func (c *Conn) updateEndpoints(why string) { c.muCond.Broadcast() }() c.dlogf("[v1] magicsock: starting endpoint update (%s)", why) - if c.noV4Send.Load() && c.derpMapHasSTUNNodes() && runtime.GOOS != "js" { + if c.noV4Send.Load() && c.shouldRebindOnFailedNetcheckV4Send() && runtime.GOOS != "js" { c.mu.Lock() closed := c.closed c.mu.Unlock() @@ -573,10 +573,10 @@ func (c *Conn) updateEndpoints(why string) { } // c.mu must NOT be held. -func (c *Conn) derpMapHasSTUNNodes() bool { +func (c *Conn) shouldRebindOnFailedNetcheckV4Send() bool { c.mu.Lock() defer c.mu.Unlock() - return c.derpMap != nil && c.derpMap.HasSTUN() + return c.derpMap != nil && c.derpMap.HasSTUN() && !c.blockEndpoints } // setEndpoints records the new endpoints, reporting whether they're changed. diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index 051ead8d0acc8..d9eb2cd12d206 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -3127,4 +3127,5 @@ func waitForNoEndpoints(t *testing.T, ms *Conn) { if !ok { t.Fatal("endpoints were not blocked after 50 attempts") } + t.Log("endpoints are blocked") }