From 30f8d8199a47b066269d961d7a4e722ce2c48194 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Tue, 25 Jun 2024 23:53:14 -0400 Subject: [PATCH] ipn/ipnlocal: fix data race in tests We can observe a data race in tests when logging after a test is finished. `b.onHealthChange` is called in a goroutine after being registered with `health.Tracker.RegisterWatcher`, which calls callbacks in `setUnhealthyLocked` in a new goroutine. See: https://github.com/tailscale/tailscale/actions/runs/9672919302/job/26686038740 Updates #12054 Signed-off-by: Andrew Dunham Change-Id: Ibf22cc994965d88a9e7236544878d5373f91229e --- ipn/ipnlocal/serve_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipn/ipnlocal/serve_test.go b/ipn/ipnlocal/serve_test.go index a09729d78..626615484 100644 --- a/ipn/ipnlocal/serve_test.go +++ b/ipn/ipnlocal/serve_test.go @@ -29,6 +29,7 @@ import ( "tailscale.com/ipn/store/mem" "tailscale.com/tailcfg" "tailscale.com/tsd" + "tailscale.com/tstest" "tailscale.com/types/logger" "tailscale.com/types/logid" "tailscale.com/types/netmap" @@ -668,7 +669,7 @@ func newTestBackend(t *testing.T) *LocalBackend { var logf logger.Logf = logger.Discard const debug = true if debug { - logf = logger.WithPrefix(t.Logf, "... ") + logf = logger.WithPrefix(tstest.WhileTestRunningLogger(t), "... ") } sys := &tsd.System{}