Merge pull request #1070 from amorken/forgotten-close

Close HTTP connections on HTTP errors too.
This commit is contained in:
Fabian Reinartz 2015-09-11 00:30:54 +02:00
commit d6ed1df4fb

View File

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