# 恐慌：向已关闭的通道发送数据

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

## 根因

在另一个goroutine关闭通道后，没有正确同步就向该通道发送数据。

## 版本兼容性

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

## 解决方案

1. **** (85% 成功率)
   ```
   Ensure the sender knows when to stop. Use a done channel to signal closure, and only close the channel from the sender side.
   ```
2. **** (90% 成功率)
   ```
   Use sync.Once to close the channel only once, ensuring no other sender attempts to send after close.
   ```

## 无效尝试

- **** — The panic is fatal and cannot be recovered; it will crash the program. (90% 失败率)
- **** — len() does not indicate whether a channel is closed, only the number of buffered elements. (95% 失败率)
- **** — The close operation may still race with the send; mutex does not prevent closing while sending. (70% 失败率)
