mirror of
https://github.com/minio/minio.git
synced 2025-08-04 21:14:30 -04:00
fix: close and drain the response body always (#8847)
This commit is contained in:
parent
3011692d93
commit
e2b3c083aa
@ -251,6 +251,7 @@ func parseDiscoveryDoc(u *xnet.URL, transport *http.Transport, closeRespFn func(
|
|||||||
}
|
}
|
||||||
resp, err := clnt.Do(req)
|
resp, err := clnt.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
clnt.CloseIdleConnections()
|
||||||
return d, err
|
return d, err
|
||||||
}
|
}
|
||||||
defer closeRespFn(resp.Body)
|
defer closeRespFn(resp.Body)
|
||||||
|
@ -304,9 +304,12 @@ func IsBackendOnline(ctx context.Context, clnt *http.Client, urlStr string) bool
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if _, err = clnt.Do(req); err != nil {
|
resp, err := clnt.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
clnt.CloseIdleConnections()
|
||||||
return !xnet.IsNetworkOrHostDown(err)
|
return !xnet.IsNetworkOrHostDown(err)
|
||||||
}
|
}
|
||||||
|
xhttp.DrainBody(resp.Body)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +66,7 @@ func (h *Target) startHTTPLogger() {
|
|||||||
|
|
||||||
resp, err := h.client.Do(req)
|
resp, err := h.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
h.client.CloseIdleConnections()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +207,7 @@ func IsServerResolvable(endpoint Endpoint) error {
|
|||||||
|
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
httpClient.CloseIdleConnections()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer xhttp.DrainBody(resp.Body)
|
defer xhttp.DrainBody(resp.Body)
|
||||||
|
@ -69,6 +69,7 @@ func (c *Client) CallWithContext(ctx context.Context, method string, values url.
|
|||||||
}
|
}
|
||||||
resp, err := c.httpClient.Do(req)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.httpClient.CloseIdleConnections()
|
||||||
return nil, &NetworkError{err}
|
return nil, &NetworkError{err}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2029,6 +2029,7 @@ func (web *webAPIHandlers) LoginSTS(r *http.Request, args *LoginSTSArgs, reply *
|
|||||||
|
|
||||||
resp, err := clnt.Do(req)
|
resp, err := clnt.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
clnt.CloseIdleConnections()
|
||||||
return toJSONError(ctx, err)
|
return toJSONError(ctx, err)
|
||||||
}
|
}
|
||||||
defer xhttp.DrainBody(resp.Body)
|
defer xhttp.DrainBody(resp.Body)
|
||||||
|
@ -142,15 +142,14 @@ func (target *WebhookTarget) send(eventData event.Event) error {
|
|||||||
|
|
||||||
resp, err := target.httpClient.Do(req)
|
resp, err := target.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
target.Close()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
io.Copy(ioutil.Discard, resp.Body)
|
io.Copy(ioutil.Discard, resp.Body)
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||||
// close any idle connections upon any error.
|
target.Close()
|
||||||
target.httpClient.CloseIdleConnections()
|
|
||||||
return fmt.Errorf("sending event failed with %v", resp.Status)
|
return fmt.Errorf("sending event failed with %v", resp.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +270,9 @@ func (adm AdminClient) do(req *http.Request) (*http.Response, error) {
|
|||||||
for {
|
for {
|
||||||
resp, err = adm.httpClient.Do(req)
|
resp, err = adm.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// Close idle connections upon error.
|
||||||
|
adm.httpClient.CloseIdleConnections()
|
||||||
|
|
||||||
// Handle this specifically for now until future Golang
|
// Handle this specifically for now until future Golang
|
||||||
// versions fix this issue properly.
|
// versions fix this issue properly.
|
||||||
urlErr, ok := err.(*url.Error)
|
urlErr, ok := err.(*url.Error)
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -100,6 +102,7 @@ func (u URL) DialHTTP() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
io.Copy(ioutil.Discard, resp.Body)
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user