go
resource_error
ai_generated
true
runtime: goroutine leak: net/http.(*persistConn).readLoop stuck
ID: go/goroutine-leak-http-body
80%Fix Rate
87%Confidence
0Evidence
2024-07-03First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.18 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
HTTP response bodies are not closed, causing persistent connection goroutines to remain blocked reading.
generic中文
HTTP 响应体未关闭,导致持久连接 goroutine 一直阻塞在读取上。
Workarounds
-
95% success
resp, err := client.Do(req) if err != nil { return err } defer resp.Body.Close() io.Copy(io.Discard, resp.Body) -
88% success
ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() req = req.WithContext(ctx)
Dead Ends
Common approaches that don't work:
-
75% fail
Timeout does not close the body; the readLoop goroutine still leaks.
-
80% fail
Reusing the client does not fix unclosed bodies.