From d791a6211dbb17e9b01c79644c1452be8016ea86 Mon Sep 17 00:00:00 2001 From: Ramon Carvalho Maciel Date: Mon, 25 Mar 2019 13:42:27 -0300 Subject: [PATCH] fix(InfluxDB): Reads body and close request body even for error status codes (#16207) --- pkg/tsdb/influxdb/influxdb.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/tsdb/influxdb/influxdb.go b/pkg/tsdb/influxdb/influxdb.go index ec1e9ff01bd..3ee6b8a30d6 100644 --- a/pkg/tsdb/influxdb/influxdb.go +++ b/pkg/tsdb/influxdb/influxdb.go @@ -4,16 +4,16 @@ import ( "context" "encoding/json" "fmt" + "io/ioutil" "net/http" "net/url" "path" - "golang.org/x/net/context/ctxhttp" - "github.com/grafana/grafana/pkg/log" "github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/tsdb" + "golang.org/x/net/context/ctxhttp" ) type InfluxDBExecutor struct { @@ -71,13 +71,14 @@ func (e *InfluxDBExecutor) Query(ctx context.Context, dsInfo *models.DataSource, return nil, err } + defer resp.Body.Close() if resp.StatusCode/100 != 2 { + ioutil.ReadAll(resp.Body) return nil, fmt.Errorf("Influxdb returned statuscode invalid status code: %v", resp.Status) } var response Response dec := json.NewDecoder(resp.Body) - defer resp.Body.Close() dec.UseNumber() err = dec.Decode(&response)