Skip to content

fix(catalog/rest): do not leak response bodies - #655

Merged
zeroshade merged 1 commit into
apache:mainfrom
ferhatelmas:ferhat/catalog-leak
Dec 23, 2025
Merged

zeroshade merged 1 commit into
apache:mainfrom
ferhatelmas:ferhat/catalog-leak

Conversation

@ferhatelmas

Copy link
Copy Markdown
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]>
Comment thread catalog/rest/rest.go
return ret, err
}
defer func() {
_, _ = io.Copy(io.Discard, rsp.Body)

Copy link
Copy Markdown
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?

@ferhatelmas ferhatelmas Dec 23, 2025 •

Copy link
Copy Markdown
Contributor Author

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
@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