Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource may leak when ReadAll meets error #30464

Closed
rleungx opened this issue Dec 7, 2021 · 1 comment · Fixed by #30462
Closed

Resource may leak when ReadAll meets error #30464

rleungx opened this issue Dec 7, 2021 · 1 comment · Fixed by #30462
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@rleungx
Copy link
Member

rleungx commented Dec 7, 2021

Bug Report

1. Minimal reproduce step (Required)

res, err = doRequestWithFailpoint(req)
metrics.PDApiExecutionHistogram.WithLabelValues("placement").Observe(time.Since(start).Seconds())
if err == nil {
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusOK {
err = errors.Errorf("%s", bodyBytes)
if res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusPreconditionFailed {
err = nil
bodyBytes = nil
}
}
terror.Log(res.Body.Close())
return bodyBytes, err
}

2. What did you expect to see? (Required)

The body should be closed when the error happens.

3. What did you see instead (Required)

The resource may leak.

4. What is your TiDB version? (Required)

master

@rleungx rleungx added the type/bug The issue is confirmed as a bug. label Dec 7, 2021
rleungx added a commit to rleungx/tidb that referenced this issue Dec 7, 2021
close pingcap#30464

Signed-off-by: Ryan Leung <rleungx@gmail.com>
@github-actions
Copy link

github-actions bot commented Dec 7, 2021

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/major sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants