go
resource_error
ai_generated
true
error: http: read on closed response body
ID: go/net-http-response-body-not-closed
80%Fix Rate
87%Confidence
0Evidence
2024-05-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.20 | active | — | — | — |
| 1.21 | active | — | — | — |
Root Cause
Reading from an HTTP response body that has already been closed, often due to premature close or double close.
generic中文
从已关闭的HTTP响应体中读取,通常由于过早关闭或重复关闭。
Workarounds
-
95% success Always defer close after checking error
resp, err := http.Get(url) if err != nil { return err } defer resp.Body.Close() // read resp.Body
Dead Ends
Common approaches that don't work:
-
Not closing response body at all
80% fail
Leads to resource leak and eventually connection pool exhaustion.