aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-08-26 13:26:57 -0700
committerGopher Robot <gobot@golang.org>2025-09-11 10:49:57 -0700
commit879e3cb5f787ed56bee2f5f4d92fd013a9b47b21 (patch)
treecac3960b5e77ea77c5c14b691f42b7f20795a448
parent56ebf80e57db9f61981fc0636fc6419dc6f68eda (diff)
downloadgo-879e3cb5f787ed56bee2f5f4d92fd013a9b47b21.tar.xz
[release-branch.go1.25] runtime: lock mheap_.speciallock when allocating synctest specials
Avoid racing use of mheap_.specialBubbleAlloc. For #75134 Fixes #75347 Change-Id: I0c9140c18d2bca1e1c3387cd81230f0e8c9ac23e Reviewed-on: https://go-review.googlesource.com/c/go/+/699255 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> (cherry picked from commit 5dcedd65504cc9cadc9a5ea8bc3af51a26eec704) Reviewed-on: https://go-review.googlesource.com/c/go/+/701797 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com>
-rw-r--r--src/internal/synctest/synctest_test.go22
-rw-r--r--src/runtime/synctest.go2
2 files changed, 24 insertions, 0 deletions
diff --git a/src/internal/synctest/synctest_test.go b/src/internal/synctest/synctest_test.go
index 307eee62e2..73a0a1c453 100644
--- a/src/internal/synctest/synctest_test.go
+++ b/src/internal/synctest/synctest_test.go
@@ -779,6 +779,28 @@ func TestWaitGroupHeapAllocated(t *testing.T) {
})
}
+// Issue #75134: Many racing bubble associations.
+func TestWaitGroupManyBubbles(t *testing.T) {
+ var wg sync.WaitGroup
+ for range 100 {
+ wg.Go(func() {
+ synctest.Run(func() {
+ cancelc := make(chan struct{})
+ var wg2 sync.WaitGroup
+ for range 100 {
+ wg2.Go(func() {
+ <-cancelc
+ })
+ }
+ synctest.Wait()
+ close(cancelc)
+ wg2.Wait()
+ })
+ })
+ }
+ wg.Wait()
+}
+
func TestHappensBefore(t *testing.T) {
// Use two parallel goroutines accessing different vars to ensure that
// we correctly account for multiple goroutines in the bubble.
diff --git a/src/runtime/synctest.go b/src/runtime/synctest.go
index 16af1209b4..529f69fd93 100644
--- a/src/runtime/synctest.go
+++ b/src/runtime/synctest.go
@@ -410,7 +410,9 @@ func getOrSetBubbleSpecial(p unsafe.Pointer, bubbleid uint64, add bool) (assoc i
} else if add {
// p is not associated with a bubble,
// and we've been asked to add an association.
+ lock(&mheap_.speciallock)
s := (*specialBubble)(mheap_.specialBubbleAlloc.alloc())
+ unlock(&mheap_.speciallock)
s.bubbleid = bubbleid
s.special.kind = _KindSpecialBubble
s.special.offset = offset