mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Close HTTP connections on HTTP errors too.
Move defer resp.Body.Close() up to make sure it's called even when the HTTP request returns something other than 200 or Decoder construction fails. This avoids leaking and eventually running out of file descriptors.
This commit is contained in:
parent
66f376f75a
commit
9fb65a91af
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue