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

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

## 根因

在派生的 goroutine 中解引用了空指针。由于 panic 发生在子 goroutine 中，会导致整个程序崩溃，父 goroutine 无法 recover。

## 版本兼容性

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

## 解决方案

1. **** (93% 成功率)
   ```
   go func() {
    defer func() {
        if r := recover(); r != nil {
            log.Printf("goroutine panic: %v", r)
        }
    }()
    doWork()
}()
   ```
2. **** (90% 成功率)
   ```
   if cfg == nil { return errors.New("nil cfg") }
go func(c Config) { use(c) }(*cfg)
   ```

## 无效尝试

- **** — recover only works in the panicking goroutine's own deferred function; the parent cannot catch it. (95% 失败率)
- **** — Race-dependent nil dereference only triggers under specific interleavings; production crashes intermittently. (80% 失败率)
