From b7cdd3e840857031baaa2ccb2eeda2e926e2a79d Mon Sep 17 00:00:00 2001 From: Bevisy Date: Sat, 25 May 2019 18:27:12 +0800 Subject: [PATCH] Exhaust request body before closing it (#5596) Signed-off-by: bevisy --- discovery/triton/triton.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/discovery/triton/triton.go b/discovery/triton/triton.go index d7a3ed3ca..cef9e1c52 100644 --- a/discovery/triton/triton.go +++ b/discovery/triton/triton.go @@ -17,6 +17,7 @@ import ( "context" "encoding/json" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -157,7 +158,10 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { return nil, errors.Wrap(err, "an error occurred when requesting targets from the discovery endpoint") } - defer resp.Body.Close() + defer func() { + io.Copy(ioutil.Discard, resp.Body) + resp.Body.Close() + }() data, err := ioutil.ReadAll(resp.Body) if err != nil {