# panic：运行时错误：无效内存地址或空指针解引用

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

## 根因

新启动的 goroutine 解引用了空指针，常见原因是捕获了尚未初始化的变量，或在赋值前访问了结构体字段。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Initialize all captured pointers before launching the goroutine, or pass values explicitly as function arguments: go func(cfg *Config) { ... }(cfg)
   ```
2. **** (88% 成功率)
   ```
   Use errgroup and return errors instead of panicking; validate pointer non-nil at goroutine entry.
   ```

## 无效尝试

- **** — Treats symptom; the goroutine still operates on invalid state and may corrupt downstream logic. (70% 失败率)
- **** — Hides the bug; other goroutines still crash and root cause is masked. (80% 失败率)
