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

Fix memory leak on read error #129

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

Exca-DK
Copy link
Contributor

@Exca-DK Exca-DK commented Feb 14, 2025

Description

This PR fixes a potential memory leak that occurs when a read error happens while processing the response body.

According to the net/http package documentation:

The caller must close the response body when finished with it.

Failing to close the response body on read errors can lead to resource leaks. This change ensures proper cleanup in such cases.

Test Plan

Testing this issue is not straightforward, as it depends on network failures. The read operation may return an error, as seen in the Go source reference.

One way to simulate this in a controlled environment is by setting an invalid Content-Length in the response header on the server side, forcing a read error:

handler := func(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Length", "1")
}

This should trigger an unexpected EOF error when reading the response body.

Related Links

None.

@Exca-DK Exca-DK requested review from gregnazario and a team as code owners February 14, 2025 23:38
Copy link
Contributor

@gregnazario gregnazario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, please update the changelog

@Exca-DK Exca-DK requested a review from gregnazario February 21, 2025 15:55
@gregnazario gregnazario merged commit 2f4a7b5 into aptos-labs:main Feb 27, 2025
1 check 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.

2 participants