go
runtime_error
ai_generated
true
panic: <custom message> [recovered by no one] — process exits with non-zero status
ID: go/panic-in-goroutine-crashes-process
80%Fix Rate
88%Confidence
0Evidence
2024-05-22First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
An unrecovered panic in any goroutine terminates the entire program. Unlike some languages, Go does not isolate goroutine panics.
generic中文
任何 goroutine 中未恢复的 panic 都会终止整个程序。与其他一些语言不同,Go 不会隔离 goroutine 的 panic。
Workarounds
-
90% success
Add 'defer func(){ recover() }()' as the first statement inside every goroutine -
85% success
Use errgroup and convert panics to errors via a recover wrapper around each task
Dead Ends
Common approaches that don't work:
-
85% fail
Sub-goroutine panics still escape and crash the process
-
95% fail
init runs in the main goroutine; cannot catch other goroutines