diff --git a/cmd/explaintest/main.go b/cmd/explaintest/main.go index ae4fa18d5a461..c81257feefb4c 100644 --- a/cmd/explaintest/main.go +++ b/cmd/explaintest/main.go @@ -425,6 +425,7 @@ func (t *tester) create(tableName string, qText string) error { if err != nil { return err } + defer resp.Body.Close() js, err := io.ReadAll(resp.Body) if err != nil { diff --git a/domain/infosync/info.go b/domain/infosync/info.go index 8596dcc6ce477..faecff8d4a8af 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -333,6 +333,7 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i } }) if err == nil { + defer terror.Call(res.Body.Close) bodyBytes, err := io.ReadAll(res.Body) if err != nil { return nil, err @@ -344,7 +345,6 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i bodyBytes = nil } } - terror.Log(res.Body.Close()) return bodyBytes, err } } @@ -694,6 +694,8 @@ func (is *InfoSyncer) getPrometheusAddr() (string, error) { if err != nil { return "", err } + defer terror.Call(resp.Body.Close) + var metricStorage metricStorage dec := json.NewDecoder(resp.Body) err = dec.Decode(&metricStorage) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index b258665f688da..4817ec694277a 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -2264,11 +2264,13 @@ func (e *TiFlashSystemTableRetriever) initialize(sctx sessionctx.Context, tiflas if err != nil { return errors.Trace(err) } - _, err = util.InternalHTTPClient().Do(req) + var r *http.Response + r, err = util.InternalHTTPClient().Do(req) if err != nil { sctx.GetSessionVars().StmtCtx.AppendWarning(err) continue } + defer terror.Call(r.Body.Close) e.instanceInfos = append(e.instanceInfos, tiflashInstanceInfo{ id: id, url: url,