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

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

## 根因

某个 goroutine 解引用了空指针，通常是因为在 goroutine 启动前结构体或 channel 字段未初始化，或在 select 中使用了 nil channel。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   s := &Service{ch: make(chan int, 1)}
go s.run()
   ```
2. **** (85% 成功率)
   ```
   if s == nil || s.ch == nil {
	return
}
// safe to use s.ch
   ```

## 无效尝试

- **** — The nil dereference indicates a real bug; recovering leaves the program in an inconsistent state and the nil access may recur. (75% 失败率)
- **** — Race conditions and ordering issues mean the pointer may still be nil when accessed; proper initialization must happen before goroutine launch. (70% 失败率)
