From c3e3819ac738823d26be9e8ec0851eb0fa9ff491 Mon Sep 17 00:00:00 2001 From: Brad Date: Sat, 26 Apr 2025 10:38:12 -0400 Subject: [PATCH] Fix: fix client tcp connection re-use by draining outstanding io --- client/transport/sse.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/transport/sse.go b/client/transport/sse.go index 501036d1e..d5abdcfe6 100644 --- a/client/transport/sse.go +++ b/client/transport/sse.go @@ -278,13 +278,19 @@ func (c *SSE) SendRequest( deleteResponseChan() return nil, fmt.Errorf("failed to send request: %w", err) } - defer resp.Body.Close() + + // Drain any outstanding io + body, err := io.ReadAll(resp.Body) + resp.Body.Close() + + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } // Check if we got an error response if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted { deleteResponseChan() - body, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, body) }