# 恐慌：关闭已关闭的通道（在 goroutine 中）

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

## 根因

两个或多个 goroutine 在没有同步的情况下尝试关闭同一个通道，导致恐慌。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use sync.Once to ensure channel is closed only once.
   ```
2. **** (90% 成功率)
   ```
   Designate a single goroutine to own the channel and close it.
   ```

## 无效尝试

- **** — Recovering doesn't solve the race; it masks the error but may leave other goroutines in inconsistent state. (80% 失败率)
- **** — Flag check is racy; another goroutine may close it between check and close. (90% 失败率)
