Skip to content

Commit

Permalink
Merge pull request #45 from coder/spike/10876-fix-close-rebind
Browse files Browse the repository at this point in the history
fix: hold magicsock mutex while rebinding to prevent race
  • Loading branch information
spikecurtis authored Dec 5, 2023
2 parents ba3acaa + f517cfd commit 61c97ba
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion wgengine/magicsock/magicsock.go
Original file line number Diff line number Diff line change
Expand Up @@ -2339,7 +2339,14 @@ func (c *Conn) rebind(curPortFate currentPortFate) error {
// It should be followed by a call to ReSTUN.
func (c *Conn) Rebind() {
metricRebindCalls.Add(1)
if err := c.rebind(keepCurrentPort); err != nil {
c.mu.Lock()
if c.closed {
c.mu.Unlock()
return
}
err := c.rebind(keepCurrentPort)
c.mu.Unlock()
if err != nil {
c.logf("%w", err)
return
}
Expand Down

0 comments on commit 61c97ba

Please sign in to comment.