go
runtime_error
ai_generated
true
panic: runtime error: invalid memory address or nil pointer dereference (in goroutine)
ID: go/goroutine-nil-pointer-dereference
80%Fix Rate
88%Confidence
0Evidence
2024-03-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.0+ | active | — | — | — |
Root Cause
A goroutine dereferences a nil pointer, often a struct field or interface that was never initialized, and the panic occurs in a goroutine so the stack trace is asynchronous.
generic中文
一个 goroutine 解引用了 nil 指针,通常是未初始化的结构体字段或接口,且 panic 发生在 goroutine 中,因此堆栈是异步的。
Workarounds
-
90% success
Initialize all struct fields in the constructor and validate inputs before spawning goroutines.
-
82% success
Add a recover that logs the stack via debug.Stack() before re-panicking or exiting, so the root cause is visible.
Dead Ends
Common approaches that don't work:
-
85% fail
The nil pointer indicates a logic bug; swallowing it leaves the program in an inconsistent state and loses the stack trace.