-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/sync/semaphore: Acquire should not wait for context to close when required weight is larger than size #59002
Comments
Why? The documented semantics of Moreover, for callers that want the early-return behavior, it is easy enough to save the original |
Yes, I agree this. If request weight is not larger than But if the request weight is larger than if n > s.size {
// Don't make other Acquire calls block on one that's doomed to fail.
s.mu.Unlock()
<-ctx.Done()
return ctx.Err()
} |
fwiw, |
I am very agree with darcy.If I did not set ctx WithTimeout , there will be a Memory leak. |
line 51 godoc WorkerPool example with |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/hqcrWEMRu-e
What did you expect to see?
This program should return immediately after compare request weight with size. For the request weight, 1000, is larger than size, 8. The request won't be fulfilled at any time.
source code: https://cs.opensource.google/go/x/sync/+/master:semaphore/semaphore.go;l=48-53;drc=43a5402ce75a95522677f77c619865d66b8c57ab
I think source code at line 51 should by removed
What did you see instead?
Waited 10 second before exit.
The text was updated successfully, but these errors were encountered: