wgengine/magicsock: synchronize test STUN shutdown.

Failure to do so triggers either a data race or a panic
in the testing package, due to racey use of t.Logf.

Signed-off-by: David Anderson <danderson@tailscale.com>
crawshaw/derpdial
David Anderson 5 years ago
parent 86baf60bd4
commit d651715528

@ -159,11 +159,17 @@ func serveSTUN(t *testing.T) (addr string, cleanupFn func()) {
stunAddr := pc.LocalAddr().String() stunAddr := pc.LocalAddr().String()
stunAddr = strings.Replace(stunAddr, "0.0.0.0:", "localhost:", 1) stunAddr = strings.Replace(stunAddr, "0.0.0.0:", "localhost:", 1)
go runSTUN(t, pc, &stats) doneCh := make(chan struct{})
return stunAddr, func() { pc.Close() } go runSTUN(t, pc, &stats, doneCh)
return stunAddr, func() {
pc.Close()
<-doneCh
}
} }
func runSTUN(t *testing.T, pc net.PacketConn, stats *stunStats) { func runSTUN(t *testing.T, pc net.PacketConn, stats *stunStats, done chan struct{}) {
defer func() { done <- struct{}{} }()
var buf [64 << 10]byte var buf [64 << 10]byte
for { for {
n, addr, err := pc.ReadFrom(buf[:]) n, addr, err := pc.ReadFrom(buf[:])

Loading…
Cancel
Save