# panic: runtime error: 无效内存地址或 nil 指针解引用 [信号 SIGSEGV]

- **ID:** `go/panic-runtime-error-invalid-memory-address-or-nil-pointer-`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

某个 goroutine 解引用了 nil 指针，通常是 goroutine 启动前未初始化的结构体字段或接口。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.18 | active | — | — |
| 1.21 | active | — | — |
| 1.22 | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   Initialize all shared pointers before launching goroutines, and capture them as arguments: go worker(cfg) where cfg is non-nil.
   ```
2. **** (85% 成功率)
   ```
   Add explicit nil checks at goroutine entry: if cfg == nil { log.Fatal("cfg is nil") }.
   ```

## 无效尝试

- **** — Recover in main does not catch panics in other goroutines; each goroutine needs its own recover, and hiding the panic masks the bug. (90% 失败率)
- **** — Creates a zero-valued object disconnected from the shared state the caller expected, causing silent logic errors. (75% 失败率)
