]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.25] runtime: lock mheap_.speciallock when allocating synctest...
authorDamien Neil <dneil@google.com>
Tue, 26 Aug 2025 20:26:57 +0000 (13:26 -0700)
committerGopher Robot <gobot@golang.org>
Thu, 11 Sep 2025 17:49:57 +0000 (10:49 -0700)
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>

src/internal/synctest/synctest_test.go
src/runtime/synctest.go

index 307eee62e2b9aa0096ce9b98fd5bb2bae2556b6d..73a0a1c453e3d5053eb2a633145030ba86074995 100644 (file)
@@ -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.
index 16af1209b4a5f70b69f44dae4ad36ea77adc165e..529f69fd9309b9e9b24179b2bfc499e922f37e40 100644 (file)
@@ -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