-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sync: unchecked overflow in (*WaitGroup).Add #20687
Comments
Change https://golang.org/cl/80835 mentions this issue: |
Is the discussion in https://golang.org/cl/80835 still up to date? |
@urld It's a worth a try though I don't know for sure what everyone will think. Thanks. |
Change https://golang.org/cl/140937 mentions this issue: |
As already mentioned in the abandoned CL, I'm not sure anymore, if it is possible to detect overflows in all cases, without turning Add into a CAS loop. Maybe there should be a variation of
If an overflow is reported during counter modification, the program could be terminated by |
Thinking about #20678 (and #19624) made me wonder what other unchecked overflows are lurking in the standard library. I've found another one, but I don't have real-world code that triggers it. (I'm filing this issue just for reference.)
(*sync.WaitGroup).Add
accepts anint
parameter, so it is reasonable for users to expect that they cannot makeAdd
calls summing to more than the maximum possibleint
. However, in practiceWaitGroup
only supportsAdd
calls that sum to withinmath.MaxInt32
.Add
currently detects (and panics on) overflows that happen to land in the negative half of theint32
space, but fails to detect other overflows entirely.Add
should be fixed to reliably panic on all overflows. It should ideally support the full positiveint
range, but if that isn't feasible the supported range should be made clear in the documentation.wgover/wgover.go:
expected (with very long running time):
actual:
The text was updated successfully, but these errors were encountered: