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) }