net/portmapper: deflake TestPCPIntegration

Logging in goroutines after the test completed
caused data races and panics. Prevent that.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
pull/3477/head
Josh Bleecher Snyder 3 years ago committed by Josh Bleecher Snyder
parent 49a9e62d58
commit 2075c39fd7

@ -63,11 +63,18 @@ type igdCounters struct {
func NewTestIGD(logf logger.Logf, t TestIGDOptions) (*TestIGD, error) {
d := &TestIGD{
logf: logf,
doPMP: t.PMP,
doPCP: t.PCP,
doUPnP: t.UPnP,
}
d.logf = func(msg string, args ...interface{}) {
// Don't log after the device has closed;
// stray trailing logging angers testing.T.Logf.
if d.closed.Get() {
return
}
logf(msg, args...)
}
var err error
if d.upnpConn, err = testListenUDP(); err != nil {
return nil, err

Loading…
Cancel
Save