global hook func for recovering

82 views
Skip to first unread message

Jérôme LAFORGE

unread,
Nov 2, 2025, 1:03:17 AM (4 days ago) Nov 2
to golang-dev
Hello Gophers,
Couple days ago, we has faced of a crash of critical service. The root cause: a panic that was not recover because a change of one developer (in this case the developer is me) that leads a global crash of the service :'(.

Is it possible to add a global hook func for recovering if it is not defined we keep the same behavior otherwise Go call it and don't crash the service with the stack trace?

Thank in advance for your support and your great job.
Jérôme

jal...@gmail.com

unread,
Nov 2, 2025, 4:05:00 PM (4 days ago) Nov 2
to golang-dev
Hi Jerome,

Unfortunately, by design, go does not provide a way to recover from panics across goroutines. recovers only work within a goroutine. So there’s currently no way to do what you are asking for. 

You would need to redesign your app to propagate recovers each time a new goroutine is spawned. If you have a crud app with http middleware, this may not be as hard as you might think. 

Joe 
Reply all
Reply to author
Forward
0 new messages