Skip to content

fix: close HTTP response body before following redirects#6183

Merged
brancz merged 2 commits intoparca-dev:mainfrom
jaffarkeikei:fix/http-body-leak-redirect
Feb 11, 2026
Merged

fix: close HTTP response body before following redirects#6183
brancz merged 2 commits intoparca-dev:mainfrom
jaffarkeikei:fix/http-body-leak-redirect

Conversation

@jaffarkeikei
Copy link

Closes the old response body before making a new redirect request to prevent resource leaks.

Before:

case 3:
    resp, err = c.doRequest(ctx, resp.Header.Get("Location"))  // Old body leaked

After:

case 3:
    redirectURL := resp.Header.Get("Location")
    resp.Body.Close()  // Close before redirect
    resp, err = c.doRequest(ctx, redirectURL)

Impact: Prevents file descriptor and memory leaks when debuginfod servers return redirects.

Fixes #6182

Closes the old response body before making a new redirect request
to prevent resource leaks (file descriptors and memory).

Fixes parca-dev#6182
@jaffarkeikei jaffarkeikei requested a review from a team as a code owner January 29, 2026 07:35
@CLAassistant
Copy link

CLAassistant commented Jan 29, 2026

CLA assistant check
All committers have signed the CLA.

When the redirect loop exits after reaching the maximum number of
redirects (2), we were returning an error without closing the last
response body, causing a resource leak.

This adds resp.Body.Close() before returning the 'too many redirects'
error to ensure the response body is properly closed in all code paths.

Fixes the test failure on amd64 architecture.

Signed-off-by: jaffar <keikei.jaffar@mail.utoronto.ca>
@brancz
Copy link
Member

brancz commented Feb 11, 2026

Apologies for the delay, I don't know why the CI jobs were suddenly running out of disk space.

@brancz brancz merged commit f58c597 into parca-dev:main Feb 11, 2026
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resource leak: HTTP response bodies not closed on redirects

3 participants