From 2703f91174120f1dba3626d2511d2e9ff3c13518 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 21 May 2026 15:33:52 +0000 Subject: [PATCH] wgengine/magicsock: fix data race in TestSetDERPMapDoReStun SetDERPMap spawns a goroutine that calls ReSTUN, which logs via the test logger. If the test returns before that goroutine logs, the goroutine races with testing cleanup. Use tstest.WhileTestRunningLogger so the goroutine's logf call becomes a no-op once the test finishes. Fixes #19829 Change-Id: I1097f98e40ffd1c5dd7fb7a715c918255853e3c6 Signed-off-by: Brad Fitzpatrick --- wgengine/magicsock/derp_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wgengine/magicsock/derp_test.go b/wgengine/magicsock/derp_test.go index c79882d54..2d1f95571 100644 --- a/wgengine/magicsock/derp_test.go +++ b/wgengine/magicsock/derp_test.go @@ -106,7 +106,9 @@ func TestSetDERPMapDoReStun(t *testing.T) { bus := eventbustest.NewBus(t) ht := health.NewTracker(bus) - c := newConn(t.Logf) + // Use WhileTestRunningLogger so the goroutine spawned by setDERPMap + // (which calls ReSTUN, which logs) doesn't race with test cleanup. + c := newConn(tstest.WhileTestRunningLogger(t)) ec := bus.Client("magicsock.Conn.Test") c.eventClient = ec c.homeDERPChangedPub = eventbus.Publish[HomeDERPChanged](ec)