sync: re-enable race even when panicking

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>
This commit is contained in:
Nicolas Hillegeer 2025-10-21 04:43:36 -07:00 committed by Gopher Robot
parent 8a6c64f4fe
commit 8f74f9daf4

View 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
}
}