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>
This commit is contained in:
Josh Bleecher Snyder 2021-12-01 10:02:15 -08:00 committed by Josh Bleecher Snyder
parent 49a9e62d58
commit 2075c39fd7

View File

@ -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