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

add defered closer calls for the http clients #705

Merged
merged 1 commit into from
Dec 9, 2020

Conversation

simskij
Copy link
Member

@simskij simskij commented Dec 9, 2020

add defered closer calls for the http client to avoid leaking file descriptors

Copy link
Member

@piksel piksel left a comment

Choose a reason for hiding this comment

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

This should at the very least apply best practice, and hopefully solve the reported FD leaks:

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.

It could be the case that the connections are being kept alive for re-use, but never actually reused because of this. But since the http.Client doesn't outlive the scope I don't think the connections would actually be reused, but that may still be the case due to some static logic in the underlying transports.
Edit: The DefaultTransport is static and reused for all http.Clients, so that is indeed the case.

Even if that were the case, this might still allow them to be closed when the client is pushed off the stack. The documentation only explicitly mentions that the Response.Body needs to be closed.

@simskij simskij merged commit ea16683 into master Dec 9, 2020
@simskij simskij deleted the fix/file-descriptors branch December 9, 2020 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants