Skip to content
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

proposal: x/sync: add panicgroup struct to deal with panic in the sub-goroutine #49802

Closed
Zh1Cheung opened this issue Nov 26, 2021 · 3 comments
Closed

Comments

@Zh1Cheung
Copy link

What did you do?

In Go,Unable to receive the panic of the sub-goroutine in the parent-goroutine.

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("recover()")
		}
		return
	}()
	g, _ := errgroup.WithContext(context.Background())
	g.Go(func() error {
		panic("this is a panic")
	})

	if err := g.Wait(); err != nil {
		fmt.Println("occur err")
		return
	}
	time.Sleep(500 * time.Millisecond)
	fmt.Println("success")
	return
}

output:

panic: this is a panic

goroutine 6 [running]:

...
...

What did you expect to see?

What I hope is that there can be a structure similar to errgroup, like panicgroup to deal with the appearance of panic in the sub-goroutine.

PS

I can implement this function if needed

@gopherbot gopherbot added this to the Unreleased milestone Nov 26, 2021
@seankhliao seankhliao changed the title x/sync: add panicgroup struct to deal with panic in the sub-goroutine proposal: x/sync: add panicgroup struct to deal with panic in the sub-goroutine Nov 26, 2021
@seankhliao
Copy link
Member

see also #40484 and CL 134395
cc @bcmills

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Nov 26, 2021
@rsc
Copy link
Contributor

rsc commented Dec 1, 2021

Seems like a duplicate of #40484, which hasn't come to a clear resolution on even proposing an API change.

@rsc rsc closed this as completed Dec 1, 2021
@rsc rsc moved this from Incoming to Declined in Proposals (old) Dec 1, 2021
@rsc
Copy link
Contributor

rsc commented Dec 1, 2021

This proposal is a duplicate of a previously discussed proposal, as noted above,
and there is no significant new information to justify reopening the discussion.
The issue has therefore been declined as a duplicate.
— rsc for the proposal review group

@golang golang locked and limited conversation to collaborators Dec 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

4 participants