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

client: RoundTrip should not close the request body, when there is no logger defined #150

Open
kayrus opened this issue Mar 19, 2021 · 1 comment

Comments

@kayrus
Copy link
Contributor

kayrus commented Mar 19, 2021

Currently the request body is closed even, when the logger is not defined:

utils/client/client.go

Lines 149 to 153 in f6de111

defer func() {
if request.Body != nil {
request.Body.Close()
}
}()

It should be closed only when the logger is defined, e.g.:

        defer func() {
                if rt.Logger != nil && request.Body != nil {
                        request.Body.Close()
                }
        }()

AFAIK it is not a big deal, because in most cases original RoundTrip closes the request body, but I think there could rare cases with bad connection, when this is not happened and this can lead to a memory leak.

@jtopjian objections, anything to add?

@jtopjian
Copy link
Contributor

jtopjian commented Mar 19, 2021

This is saying that if the logger is not nil, then the body will not be closed.

My understanding is that the roundtripper should ensure that the body is closed (I could be wrong about this). If we add this conditional, does it actually increase the chances that the body isn't closed?

If we're not sure, maybe it's best to stick with the devil we know?

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

No branches or pull requests

2 participants