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

webhooks: discarding body after http requests in order to allow reusi… #1061

Merged
merged 1 commit into from May 19, 2022

Conversation

gosom
Copy link
Contributor

@gosom gosom commented May 9, 2022

when you do more than 1 call using the provided http client, the connection won't be reused and a new potentially expensive TCP connection will be established.

In order for the connection to be reused by the Transport you need to read the response body in full and close the response.

this is from the go source code comment [https://pkg.go.dev/net/http]:

// The http Client and Transport guarantee that Body is always
// non-nil, even on responses without a body or responses with
// a zero-length body. 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.

Note:
ioutil.Discard is used but if the lib supports golang >= 1.16 then it should become io.Discard.
Additionally, ioutil.Discard is used in other places that's why I picked that.

Best

Copy link
Member

@kanata2 kanata2 left a comment

Choose a reason for hiding this comment

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

Thanks!

@kanata2 kanata2 merged commit 34c7fd3 into slack-go:master May 19, 2022
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