mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
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>
This commit is contained in:
parent
86baf60bd4
commit
d651715528
@ -159,11 +159,17 @@ func serveSTUN(t *testing.T) (addr string, cleanupFn func()) {
|
||||
stunAddr := pc.LocalAddr().String()
|
||||
stunAddr = strings.Replace(stunAddr, "0.0.0.0:", "localhost:", 1)
|
||||
|
||||
go runSTUN(t, pc, &stats)
|
||||
return stunAddr, func() { pc.Close() }
|
||||
doneCh := make(chan struct{})
|
||||
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
|
||||
for {
|
||||
n, addr, err := pc.ReadFrom(buf[:])
|
||||
|
Loading…
Reference in New Issue
Block a user