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

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

## 根因

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

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Initialize all pointers before spawning the goroutine and prefer value receivers:

cfg := &Config{}
go worker(cfg) // cfg is non-nil
   ```
2. **** (92% 成功率)
   ```
   Add nil guards at goroutine entry and return early with an error:

if s == nil {
    return errors.New("nil service")
}
   ```

## 无效尝试

- **** — The nil deref indicates a logic bug; swallowing it leaves the goroutine's work incomplete and can corrupt state. (80% 失败率)
- **** — Hides diagnostics; the crash still terminates the program. (95% 失败率)
