From 4f90d592fd8785fffc15130714a2ec2369448189 Mon Sep 17 00:00:00 2001 From: Yahor Yuzefovich Date: Wed, 4 Dec 2024 20:24:06 -0800 Subject: [PATCH] sql: fix a race in TestShowTenantFingerprintsProtectsTimestamp I think there is a possible race in `TestShowTenantFingerprintsProtectsTimestamp` where we have an atomic to make sure that we close the channel only once. If we have concurrent BatchRequests checking the `if` condition at the same time, both will try to close the channel leading to a panic. Switch to using compare-and-swap instead of load plus store. Release note: None --- pkg/sql/show_fingerprints_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/sql/show_fingerprints_test.go b/pkg/sql/show_fingerprints_test.go index e82a5d7efc17..eb95f1f7c2a3 100644 --- a/pkg/sql/show_fingerprints_test.go +++ b/pkg/sql/show_fingerprints_test.go @@ -149,8 +149,7 @@ func TestShowTenantFingerprintsProtectsTimestamp(t *testing.T) { testingRequestFilter := func(_ context.Context, ba *kvpb.BatchRequest) *kvpb.Error { for _, req := range ba.Requests { if expReq := req.GetExport(); expReq != nil { - if expReq.ExportFingerprint && !exportStartedClosed.Load() { - exportStartedClosed.Store(true) + if expReq.ExportFingerprint && exportStartedClosed.CompareAndSwap(false, true) { close(exportsStarted) <-exportsResume }