Skip to content

Commit 2915b79

Browse files
authored
Fix: fix client tcp connection re-use by draining outstanding io (#212)
1 parent b7ab1cf commit 2915b79

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

client/transport/sse.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,19 @@ func (c *SSE) SendRequest(
278278
deleteResponseChan()
279279
return nil, fmt.Errorf("failed to send request: %w", err)
280280
}
281-
defer resp.Body.Close()
281+
282+
// Drain any outstanding io
283+
body, err := io.ReadAll(resp.Body)
284+
resp.Body.Close()
285+
286+
if err != nil {
287+
return nil, fmt.Errorf("failed to read response body: %w", err)
288+
}
282289

283290
// Check if we got an error response
284291
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {
285292
deleteResponseChan()
286293

287-
body, _ := io.ReadAll(resp.Body)
288294
return nil, fmt.Errorf("request failed with status %d: %s", resp.StatusCode, body)
289295
}
290296

0 commit comments

Comments
 (0)