From fe2f89deab656a9491bc09cbf81d90e519c265af Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 27 Aug 2021 14:13:49 -0700 Subject: [PATCH] wgengine/magicsock: fix rare shutdown race in test. Signed-off-by: David Anderson --- wgengine/magicsock/magicsock.go | 4 +++- wgengine/magicsock/magicsock_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index f78002795..9fd83f1a7 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -3208,7 +3208,9 @@ func ippDebugString(ua netaddr.IPPort) string { } // discoEndpoint is a wireguard/conn.Endpoint that picks the best -// available path to communicate with a peer. +// available path to communicate with a peer, based on network +// conditions and what the peer supports. In particular, despite the +// name, an endpoint can support DERP only. type discoEndpoint struct { // atomically accessed; declared first for alignment reasons lastRecv mono.Time diff --git a/wgengine/magicsock/magicsock_test.go b/wgengine/magicsock/magicsock_test.go index 7a9153c7d..7b1b96927 100644 --- a/wgengine/magicsock/magicsock_test.go +++ b/wgengine/magicsock/magicsock_test.go @@ -290,11 +290,19 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM m.conn.UpdatePeers(peerSet) wg, err := nmcfg.WGCfg(nm, logf, netmap.AllowSingleHosts, "") if err != nil { + if ctx.Err() != nil { + // shutdown race, don't care. + return + } // We're too far from the *testing.T to be graceful, // blow up. Shouldn't happen anyway. panic(fmt.Sprintf("failed to construct wgcfg from netmap: %v", err)) } if err := m.Reconfig(wg); err != nil { + if ctx.Err() != nil { + // shutdown race, don't care. + return + } panic(fmt.Sprintf("device reconfig failed: %v", err)) } }