go
runtime_error
ai_generated
true
panic: runtime error: invalid memory address or nil pointer dereference (in goroutine)
ID: go/panic-runtime-error-invalid-memory-address-nil-pointer-in-goroutine
80%Fix Rate
90%Confidence
0Evidence
2024-09-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
A goroutine dereferences a nil pointer; because it runs in a background goroutine, the panic crashes the whole program.
generic中文
某个 goroutine 解引用 nil 指针;由于运行在后台 goroutine 中,panic 会导致整个程序崩溃。
Workarounds
-
90% success
go func() { defer func() { if r := recover(); r != nil { log.Printf("panic: %v", r) } }() doWork() }() -
93% success
if p == nil { return fmt.Errorf("nil receiver") }
Dead Ends
Common approaches that don't work:
-
95% fail
Panic happens in a child goroutine; recover in main never sees it.
-
90% fail
Any unhandled panic in a goroutine terminates the process.