# runtime: goroutine 数量无限增长（通过 runtime.NumGoroutine() 观测）

- **ID:** `go/goroutine-leak-pprof`
- **领域:** go
- **类别:** resource_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

goroutine 永远阻塞在 channel 发送/接收上，或等待一个永不取消的 context，因此永不退出。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   go func(ctx context.Context) {
    select {
    case <-ctx.Done():
        return
    case work <- job:
    }
}(ctx)
   ```
2. **** (88% 成功率)
   ```
   import _ "net/http/pprof"
// go tool pprof http://localhost:6060/debug/pprof/goroutine
   ```

## 无效尝试

- **** — GC does not kill blocked goroutines. (95% 失败率)
- **** — Delays OOM but goroutines still accumulate. (85% 失败率)
