Skip to content

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 <[email protected]>
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