oguzbilgic / pandik

monitoring tool for web services
MIT License
177 stars 14 forks source link

checkHTTPStatus should close the request Body? #3

Closed justinas closed 11 years ago

justinas commented 11 years ago

I'm not entirely sure of this, as checkHTTPStatus doesn't actually read anything from the body, but you might want to defer resp.Body.Close() here.

Go docs for net/http say:

Callers should close resp.Body when done reading from it. If resp.Body is not 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.

Basically, I think the code as it is now might leave TCP connections open (at least until they're killed by the server). I haven't actually tested it yet though.

And as we're not reading anything from the Body, we're "done reading from it" immediately after the request has been returned, I guess.

oguzbilgic commented 11 years ago

Thanks for the heads up. Give me sometime to make some research about this. I think best way to clarify this will be doing some tests.