# panic: runtime error: 无效内存地址或 nil 指针解引用 [signal SIGSEGV...]（位于 goroutine N）

- **ID:** `go/goroutine-nil-pointer-in-goroutine`
- **领域:** go
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

goroutine 解引用了 nil 指针，通常是因为它捕获了尚未赋值的变量，或结构体字段未初始化。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   for _, item := range items {
    item := item
    go func(it *Item) {
        process(it)
    }(&item)
}
   ```
2. **** (92% 成功率)
   ```
   svc := &Service{Client: newClient()}
go svc.Run()
   ```

## 无效尝试

- **** — If the nil is a logic error (e.g., missing initialization), skipping the work silently hides the bug. (60% 失败率)
- **** — Recovering prevents a crash but does not fix the root cause; the same nil deref will recur. (80% 失败率)
