# 恐慌：关闭已关闭的通道

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

## 根因

尝试关闭已经关闭的通道，通常由于多个goroutine没有协调就关闭通道。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Use sync.Once to ensure the channel is closed only once.
   ```
2. **** (90% 成功率)
   ```
   Have a single owner goroutine that is responsible for closing the channel.
   ```

## 无效尝试

- **** — The panic is fatal and cannot be recovered; it will crash the program. (90% 失败率)
- **** — Checking a flag is racy; the channel may be closed between the check and the close call. (85% 失败率)
- **** — The mutex ensures only one goroutine closes, but it does not prevent closing an already closed channel if the logic is wrong. (60% 失败率)
