Skip to content

Commit 0678053

Browse files
fix(transport): close response body on 404 in sendHTTP (#849)
When sendHTTP receives a 404 (session terminated), it returns (nil, ErrSessionTerminated) without closing resp.Body. All four callers (SendRequest, SendNotification, createGETConnectionToServer, sendResponseToServer) defer resp.Body.Close() only after checking err == nil, so the body is never closed. Under listenForever retry loops, each 404 leaks one TCP connection. On long-running clients this eventually exhausts file descriptors. Fix: close resp.Body before returning on the 404 path.
1 parent 083b8ac commit 0678053

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

client/transport/streamable_http.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ func (c *StreamableHTTP) sendHTTP(
678678

679679
// universal handling for session terminated
680680
if resp.StatusCode == http.StatusNotFound {
681+
resp.Body.Close()
681682
c.sessionID.CompareAndSwap(sessionID, "")
682683
return nil, ErrSessionTerminated
683684
}

0 commit comments

Comments
 (0)