# panic: 运行时错误: 无效内存地址或 nil 指针解引用（在 goroutine 中）

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

## 根因

一个 goroutine 解引用了 nil 指针，通常是未初始化的结构体字段或接口，且 panic 发生在 goroutine 中，因此堆栈是异步的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.0+ | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Initialize all struct fields in the constructor and validate inputs before spawning goroutines.
   ```
2. **** (82% 成功率)
   ```
   Add a recover that logs the stack via debug.Stack() before re-panicking or exiting, so the root cause is visible.
   ```

## 无效尝试

- **** — The nil pointer indicates a logic bug; swallowing it leaves the program in an inconsistent state and loses the stack trace. (85% 失败率)
