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

Use cleanhttp.DefaultPooledConnection and enforce cleanup #57

Merged
merged 3 commits into from
Aug 26, 2019
Merged

Conversation

jefferai
Copy link
Member

@jefferai jefferai commented May 7, 2019

This allows reuse of the existing connection on retries, since they're
going to the same host, but we explicitly close idle connections to
ensure they don't stick around forever after the series of requests is
done.

Fixes #44

This allows reuse of the existing connection on retries, since they're
going to the same host, but we explicitly close idle connections to
ensure they don't stick around forever after the series of requests is
done.

Fixes #44
@jefferai jefferai requested review from ryanuber and evanphx May 7, 2019 11:19
@@ -422,6 +427,7 @@ func (c *Client) Do(req *Request) (*http.Response, error) {
if checkErr != nil {
err = checkErr
}
c.HTTPClient.CloseIdleConnections()
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be here. This branch is when good requests are returned and closing idle here will make it mostly useless. You could probably safely move this up 2 lines inside check checkErr if so it's only run if we're running with an error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why do we not want to close idle connections if it's successful?

Before this patch we have keepalives totally disabled. Closing idle connections in all cases preserves that behavior except when actively retrying.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the point of this patch was to leave connections alive so that future ones are faster?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but scoped only to the library's own retries.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok.

Copy link

Choose a reason for hiding this comment

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

This breaks compatibility with Go < v1.12, HTTPClient.CloseIdleConnections was only added in v1.12 😿

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.

Mention use of cleanhttp which by default disables keepalives
3 participants