diff --git a/br/pkg/restore/split_client.go b/br/pkg/restore/split_client.go index e5105a56dc603..10a9913d8e683 100755 --- a/br/pkg/restore/split_client.go +++ b/br/pkg/restore/split_client.go @@ -416,6 +416,11 @@ func (c *pdClient) getMaxReplica(ctx context.Context) (int, error) { if err != nil { return 0, errors.Trace(err) } + defer func() { + if err = res.Body.Close(); err != nil { + log.Error("Response fail to close", zap.Error(err)) + } + }() var conf config.Config if err := json.NewDecoder(res.Body).Decode(&conf); err != nil { return 0, errors.Trace(err) @@ -482,11 +487,15 @@ func (c *pdClient) GetPlacementRule(ctx context.Context, groupID, ruleID string) if err != nil { return rule, errors.Trace(err) } + defer func() { + if err = res.Body.Close(); err != nil { + log.Error("Response fail to close", zap.Error(err)) + } + }() b, err := io.ReadAll(res.Body) if err != nil { return rule, errors.Trace(err) } - res.Body.Close() err = json.Unmarshal(b, &rule) if err != nil { return rule, errors.Trace(err)