go
resource_error
ai_generated
true
错误:http:在已关闭的响应体上读取
error: http: read on closed response body
ID: go/net-http-response-body-not-closed
80%修复率
87%置信度
0证据数
2024-05-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
根因分析
从已关闭的HTTP响应体中读取,通常由于过早关闭或重复关闭。
English
Reading from an HTTP response body that has already been closed, often due to premature close or double close.
解决方案
-
95% 成功率 Always defer close after checking error
resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() // read resp.Body
无效尝试
常见但无效的做法:
-
Not closing response body at all
80% 失败
Leads to resource leak and eventually connection pool exhaustion.