go
runtime_error
ai_generated
true
panic: 向已关闭的 channel 发送数据(在 select 语句中)
panic: send on closed channel (inside select statement)
ID: go/send-on-closed-channel-select
80%修复率
88%置信度
0证据数
2024-05-01首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
根因分析
select 的某个 case 尝试向已被其他 goroutine 关闭的 channel 发送数据,尽管通常认为 select 能保护发送操作。
English
A select case attempts to send on a channel that has been closed by another goroutine, even though select is often assumed to protect sends.
解决方案
-
90% 成功率
select { case ch <- v: case <-done: return } -
92% 成功率
// only the owner closes; producers send via a request channel
无效尝试
常见但无效的做法:
-
90% 失败
default does not prevent the panic when the send case is selected and the channel is closed.
-
85% 失败
Buffering delays but does not prevent the panic; a closed channel rejects all sends regardless of buffer.