go
runtime_error
ai_generated
true
http: request body already closed
ID: go/http-request-body-already-closed
80%Fix Rate
85%Confidence
0Evidence
2024-03-15First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
| 1.22 | active | — | — | — |
Root Cause
Attempting to read from or close an http.Request.Body that has already been closed, typically due to double-close or reading after the handler has returned.
generic中文
尝试读取或关闭已经关闭的http.Request.Body,通常是由于重复关闭或处理器返回后继续读取。
Workarounds
-
95% success
if body, err := io.ReadAll(r.Body); err == nil { r.Body.Close() } -
90% success
defer r.Body.Close() once at start of handler
Dead Ends
Common approaches that don't work:
-
80% fail
Silently ignoring leads to incomplete reads and potential data corruption
-
90% fail
Request body is a stream and cannot be reopened; must be buffered upfront if multiple reads needed