Skip to content

Commit 74c07cf

Browse files
Merge pull request #8560 from vismishr/OCPBUGS-86025/fix-http-body-close
OCPBUGS-86025: Close HTTP response bodies to prevent goroutine and connection leaks
2 parents e680e1d + 590978b commit 74c07cf

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

support/konnectivityproxy/dialer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,15 @@ func (p *konnectivityProxy) DialContext(ctx context.Context, network string, req
328328
}
329329
if res.StatusCode != http.StatusOK {
330330
log.Info("Status code was not 200", "statusCode", res.StatusCode)
331+
res.Body.Close()
331332
_ = konnectivityConnection.Close()
332333
return nil, fmt.Errorf("proxy error from %s while dialing %s: %v", konnectivityServerAddress, requestAddress, res.Status)
333334
}
334335
// It's safe to discard the bufio.Reader here and return the original TCP conn directly because we only use this
335336
// for TLS. In TLS, the client speaks first, so we know there's no unbuffered data, but we can double-check.
336337
if br.Buffered() > 0 {
337338
log.Info("The response contained buffered data, none expected")
339+
res.Body.Close()
338340
_ = konnectivityConnection.Close()
339341
return nil, fmt.Errorf("unexpected %d bytes of buffered data from CONNECT proxy %q",
340342
br.Buffered(), konnectivityServerAddress)

support/konnectivityproxy/proxy_dialer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func (hpd *httpProxyDialer) Dial(network string, addr string) (net.Conn, error)
6161
}
6262

6363
if resp.StatusCode != http.StatusOK {
64+
resp.Body.Close()
6465
conn.Close()
6566
f := strings.SplitN(resp.Status, " ", 2)
6667
return nil, errors.New(f[1])

0 commit comments

Comments
 (0)