Skip to content

Commit

Permalink
Avoid constant rebinding on blocked endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
deansheather committed Dec 12, 2023
1 parent 614a18f commit 2cdd5b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions wgengine/magicsock/magicsock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 2cdd5b8

Please sign in to comment.