Skip to content

Commit e8e292e

Browse files
Fix race condition in concurrent decrypt benchmark
1 parent 0c7cbd3 commit e8e292e

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

go/appencryption/concurrent_benchmark_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ func BenchmarkSession_Decrypt_Concurrent(b *testing.B) {
5656
drrs[i] = drr
5757
}
5858

59+
var counter int64
60+
5961
b.ResetTimer()
6062
b.RunParallel(func(pb *testing.PB) {
61-
idx := 0
6263
for pb.Next() {
63-
// Use round-robin to select DRR copies
64+
// Use atomic counter for round-robin to avoid race
65+
idx := atomic.AddInt64(&counter, 1)
6466
_, err := session.Decrypt(ctx, *drrs[idx%numCopies])
6567
if err != nil {
6668
b.Error(err)
6769
}
68-
idx++
6970
}
7071
})
7172
}

0 commit comments

Comments
 (0)