go
runtime_error
ai_generated
true
panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x...]
ID: go/nil-pointer-in-goroutine
80%Fix Rate
86%Confidence
0Evidence
2024-05-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.16+ | active | — | — | — |
Root Cause
A goroutine dereferences a nil pointer, often because a shared struct field or captured variable was set to nil by another goroutine, or the goroutine started before its dependency was initialized.
generic中文
goroutine 解引用了空指针,通常是因为共享结构体字段或被捕获的变量被另一个 goroutine 置为 nil,或 goroutine 在依赖初始化之前就启动了。
Workarounds
-
90% success
mu.Lock() local := cfg mu.Unlock() if local == nil { return errors.New("cfg not initialized") } local.Do() -
87% success
cfg := loadConfig() go func(c *Config) { if c == nil { return } c.Do() }(cfg)
Dead Ends
Common approaches that don't work:
-
80% fail
Silently dropping the panic leaves the program in an inconsistent state and the nil root cause is never fixed.
-
75% fail
The pointer may be mutated to nil by another goroutine after the check, so a TOCTOU race still crashes.