diff --git a/retrieval/target.go b/retrieval/target.go index b9d9abe2e..c37ce2f66 100644 --- a/retrieval/target.go +++ b/retrieval/target.go @@ -437,6 +437,8 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) { if err != nil { return err } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK { return fmt.Errorf("server returned HTTP status %s", resp.Status) } @@ -445,7 +447,6 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) { if err != nil { return err } - defer resp.Body.Close() sdec := expfmt.SampleDecoder{ Dec: dec,