From 76ad9d7a7abbc5162080eb686070c5f2731e74ad Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sat, 16 Oct 2021 13:59:13 -0700 Subject: [PATCH] wgengine/magicsock: don't Rebind after STUN error if closed. https://github.com/tailscale/tailscale/pull/3014 added a rebind on STUN failure, which means there can now be a tailscale.com/wgengine/magicsock.(*RebindingUDPConn).ReadFromNetaddr in progress at the end of the test waiting for a STUN response which will never arrive. This causes a test flake due to the resource leak in those cases where the Conn decided to rebind. For whatever reason, it mostly flakes with Windows. If the Conn is closed, don't Rebind after a send error. Signed-off-by: Denton Gentry (cherry picked from commit def650b3e8486ad513cf59a53abd40dfbd3ec4cd) --- wgengine/magicsock/magicsock.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 13bfd308a..9d16c6e8b 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -616,8 +616,13 @@ func (c *Conn) updateEndpoints(why string) { }() c.logf("[v1] magicsock: starting endpoint update (%s)", why) if c.noV4Send.Get() { - c.logf("magicsock: last netcheck reported send error. Rebinding.") - c.Rebind() + c.mu.Lock() + closed := c.closed + c.mu.Unlock() + if !closed { + c.logf("magicsock: last netcheck reported send error. Rebinding.") + c.Rebind() + } } endpoints, err := c.determineEndpoints(c.connCtx)