Exhaust request body before closing it (#5596)

Signed-off-by: bevisy <binbin36520@gmail.com>
This commit is contained in:
Bevisy 2019-05-25 18:27:12 +08:00 committed by beorn7
parent 2548271e0f
commit 70b2be3907
1 changed files with 5 additions and 1 deletions

View File

@ -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 {