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: runtime: add a function to install a global go-routine panic handler #55038

Closed
markusheukelom opened this issue Sep 13, 2022 · 6 comments
Labels
FrozenDueToAge Proposal WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@markusheukelom
Copy link

package runtime

// Recover installs a handler function that is called whenever a panicking sequence
// in any Go routine is not stopped by a call to recover in a locally deferred function call. 
//
// If no handler function is installed the program aborts.
//
// By default, no handler function is installed.
// 
// The handler function runs as if a defer-recover preamble was added to the function on 
// which the `go` operatorr is invoked:
//  
//     defer func() { if r := recover(); r != nil { handler(r) } }
//
// This means that, for example, the stack of the panicking go-routine can be retrieved use `debug.Stack`, etc.
func Recover(handler func(r any)) {}
@gopherbot gopherbot added this to the Proposal milestone Sep 13, 2022
@mvdan
Copy link
Member

mvdan commented Sep 13, 2022

Please note that you should fill https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing a language change. I realise that this is technically not a language change, but this is still a substantial change to how recover works in practice, which is a part of the language.

@mvdan mvdan added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 13, 2022
@wizardishungry
Copy link

Why not introduce a function that lets you override go itself:

func Go(handler func(
  goF func(func()),
  f func() ,
))

Calls to go f() will be passed to handler with a goF argument corresponding to the built-in implementation of go.

@seankhliao
Copy link
Member

Duplicate of #32333

@seankhliao seankhliao marked this as a duplicate of #32333 Sep 13, 2022
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 13, 2022
@markusheukelom
Copy link
Author

@wizardishungry I'm not completely sure I understand your suggestion, but if mean to say "just write a wrapper function": this is indeed easy. But the problem is that you cannot require its usage and so code that you don't have control over (or did not review throughly) can still easily crash an entire program. I think this is also described in the linked duplicate issue.

We run a "modular monolith" which works really great, except that every once in a while I (or team members) for get to do a defer+recover in a function that is invoke as go-routine. The modules would be better encapsulated if uncaught panic in one go-routine did not crash all other "modules" (ie. the program).

@wizardishungry
Copy link

Right – What I'm suggesting is that you be able to register a global wrapper function.

@rsc
Copy link
Contributor

rsc commented Mar 29, 2023

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 Mar 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Proposal WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants