-
Notifications
You must be signed in to change notification settings - Fork 18k
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/errgroup: why not recover the fn's err in errgroup #40484
Comments
CL 134395 does propagate panics to the caller of |
looking forward to it. |
I'd prefer the current behavior - if there is a panic, the program should crash. Please note that the user can change the current behavior of this library using a tiny wrapper around it that recovers from panics, but if the library changes the behavior it'd be impossible to reverse it. Please let the user choose what their program should do. |
@ash2k, it is possible for a library to change the behavior either way. Consider: func unrecover(f func()) {
defer func() {
if r := recover(); r != nil {
go panic(r) // Move the panic to a new goroutine so that it cannot be recovered.
}
}()
f()
} |
@bcmills Yes, but |
Perhaps we may make recover as an option when defer func() {
if g.recover {
if err := recover(); err != nil {
stack := string(debug.Stack())
fmt.Println(stack)
}
}
g.wg.Done()
}() |
I have a CLI tool that uses errgroup and ends with the following (or similar): if err := group.Wait(); err != nil {
log.Fatalf("error: %v", err)
} The problem is that the last group (the slowest) was panic-ing, which would default to I have created a go playground demo for this: Run it multiple times (at least 5-10 times) to see that the outcome is inconsistent. The |
Change https://go.dev/cl/416555 mentions this issue: |
I have filed #53757 as a concrete proposal to address Since this issue only raises the question of why the current API is the way it is, I am closing this issue as inactionable. |
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?
we all know that use goroutine without a recover, the go program may cause a crash
What did you expect to see?
I expect that errgroup can recover the fn's error silently.
What is the reason not to do so? Is recover may decrease the performance of the program?
What did you see instead?
I should add
defer func(){recover()}()
inside the go func every time I use errgroupThe text was updated successfully, but these errors were encountered: