From 6d1179960edececae4e148faab12d7646c8a7d1e Mon Sep 17 00:00:00 2001 From: Vidit Bhat Date: Tue, 24 Sep 2024 21:15:22 +0530 Subject: [PATCH] testutils: data race when TestCluster fails to start Previously, we were running into a race condition due to the access of the `stores` map in the error reporting inside the timeout logic. This patch fixes this by reporting the error after grabbing a lock on `stores`. Epic: none Fixes: #87592 Release note: None --- pkg/testutils/testcluster/testcluster.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/testutils/testcluster/testcluster.go b/pkg/testutils/testcluster/testcluster.go index 53b45750661b..0529cc1913bc 100644 --- a/pkg/testutils/testcluster/testcluster.go +++ b/pkg/testutils/testcluster/testcluster.go @@ -685,7 +685,11 @@ func (tc *TestCluster) WaitForNStores(t serverutils.TestFataler, n int, g *gossi } t.Fatal(err) case <-time.After(testutils.DefaultSucceedsSoonDuration): - t.Fatalf("timed out waiting for %d store descriptors: %v", n-seen, stores) + func() { + storesMu.Lock() + defer storesMu.Unlock() + t.Fatalf("timed out waiting for %d store descriptors: %v", n-seen, stores) + }() } } }