Skip to content

Conversation

@ferhatelmas
Copy link
Contributor

In error case, body isn't closed so
underlying TCP connection might not be used.
Defer closing and draining unconditionally
for safer and more idiomatic handling.

In error case, body isn't closed so
underlying TCP connection might not be used.
Defer closing and draining unconditionally
for safer and more idiomatic handling.

Signed-off-by: ferhat elmas <[email protected]>
return ret, err
}
defer func() {
_, _ = io.Copy(io.Discard, rsp.Body)
Copy link
Member

Choose a reason for hiding this comment

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

is this actually necessary? Isn't rsp.Body.Close() sufficient?

Copy link
Contributor Author

@ferhatelmas ferhatelmas Dec 23, 2025

Choose a reason for hiding this comment

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

no it should be consumed per https://pkg.go.dev/net/http#Response

// It is the caller's responsibility to
// close Body. The default HTTP client's Transport may not
// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
// not read to completion and closed.

@zeroshade zeroshade merged commit 297fb2c into apache:main Dec 23, 2025
11 checks passed
@ferhatelmas ferhatelmas deleted the ferhat/catalog-leak branch December 23, 2025 16:45
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