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

Response body not always fully read #176

Open
eitankatznelson opened this issue Nov 1, 2021 · 1 comment
Open

Response body not always fully read #176

eitankatznelson opened this issue Nov 1, 2021 · 1 comment

Comments

@eitankatznelson
Copy link

The http.Do function documentation states that:

// If the returned error is nil, the Response will contain a non-nil
// Body which the user is expected to close. If the Body is not both
// read to EOF and closed, the Client's underlying RoundTripper
// (typically Transport) may not be able to re-use a persistent TCP
// connection to the server for a subsequent "keep-alive" request.

In the report method, if the response code is <300 the client doesn't read the response body causing connections to get closed by servers.

Simple fix would be to add the line:
ioutil.ReadAll(res.Body)
in the condition block.

@defrankland
Copy link

I can also confirm that this is an issue. I was seeing an error from this package:

ERROR: sending request - Post "https://api.segment.io/v1/batch": write on closed buffer

Which I resolved by forking this repo and adding io.Copy(ioutil.Discard, resp.Body) to discard the body in the block where the response body is not currently being read.

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