go
network_error
ai_generated
true
http: write on closed connection
ID: go/http-write-after-shutdown
80%Fix Rate
87%Confidence
0Evidence
2024-08-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.21 | active | — | — | — |
Root Cause
Attempting to write a response to a client connection that has already been closed, often due to a timeout or client disconnect.
generic中文
尝试向已关闭的客户端连接写入响应,通常是由于超时或客户端断开连接。
Workarounds
-
85% success
if err := json.NewEncoder(w).Encode(data); err != nil { log.Printf("Error writing response: %v", err) } -
80% success
Use context cancellation to detect client disconnects early.
Dead Ends
Common approaches that don't work:
-
70% fail
The write will fail silently, and the client will never receive the response.
-
90% fail
The issue is not buffer size but connection state.