]> Cypherpunks repositories - gostls13.git/commitdiff
sync: re-enable race even when panicking
authorNicolas Hillegeer <aktau@google.com>
Tue, 21 Oct 2025 11:43:36 +0000 (04:43 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 21 Oct 2025 18:27:38 +0000 (11:27 -0700)
Not doing this can cause user code running after this panic (e.g.:
defers) to produce non-existing races.

Change-Id: Ia6aec88aaeee3b9c17e7b8019d697ffa88dfb492
Reviewed-on: https://go-review.googlesource.com/c/go/+/713460
Commit-Queue: Nicolas Hillegeer <aktau@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Nicolas Hillegeer <aktau@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/sync/waitgroup.go

index 5b035aa3967ad35e632d6acd5548b657eff1bdd5..195f839da417bdc4c3deb30e050b9c3e44cf6478 100644 (file)
@@ -204,13 +204,14 @@ func (wg *WaitGroup) Wait() {
                                }
                        }
                        runtime_SemacquireWaitGroup(&wg.sema, synctestDurable)
-                       if wg.state.Load() != 0 {
-                               panic("sync: WaitGroup is reused before previous Wait has returned")
-                       }
+                       isReset := wg.state.Load() != 0
                        if race.Enabled {
                                race.Enable()
                                race.Acquire(unsafe.Pointer(wg))
                        }
+                       if isReset {
+                               panic("sync: WaitGroup is reused before previous Wait has returned")
+                       }
                        return
                }
        }