go
network_error
ai_generated
true
http:在已关闭的连接上写入
http: write on closed connection
ID: go/http-write-after-shutdown
80%修复率
87%置信度
0证据数
2024-08-02首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
根因分析
尝试向已关闭的客户端连接写入响应,通常是由于超时或客户端断开连接。
English
Attempting to write a response to a client connection that has already been closed, often due to a timeout or client disconnect.
解决方案
-
85% 成功率
if err := json.NewEncoder(w).Encode(data); err != nil { log.Printf("Error writing response: %v", err) } -
80% 成功率
Use context cancellation to detect client disconnects early.
无效尝试
常见但无效的做法:
-
70% 失败
The write will fail silently, and the client will never receive the response.
-
90% 失败
The issue is not buffer size but connection state.