mirror of
https://github.com/minio/minio.git
synced 2025-11-10 05:59:43 -05:00
fix: close and drain the response body always (#8847)
This commit is contained in:
@@ -142,15 +142,14 @@ func (target *WebhookTarget) send(eventData event.Event) error {
|
||||
|
||||
resp, err := target.httpClient.Do(req)
|
||||
if err != nil {
|
||||
target.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
|
||||
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
||||
// close any idle connections upon any error.
|
||||
target.httpClient.CloseIdleConnections()
|
||||
target.Close()
|
||||
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 {
|
||||
resp, err = adm.httpClient.Do(req)
|
||||
if err != nil {
|
||||
// Close idle connections upon error.
|
||||
adm.httpClient.CloseIdleConnections()
|
||||
|
||||
// Handle this specifically for now until future Golang
|
||||
// versions fix this issue properly.
|
||||
urlErr, ok := err.(*url.Error)
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -100,6 +102,7 @@ func (u URL) DialHTTP() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
io.Copy(ioutil.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user