On Sep 16, 2014, at 5:36 PM, Jesse McNelis wrote:
On Wed, Sep 17, 2014 at 8:00 AM, James Bardin wrote:
I feel like I've seen it mentioned somewhere that you don't need to close an
http.Response.Body if you didn't use the response.
But, I can't find that anywhere in the official docs.

The docs say (currently) "Caller should close resp.Body when done reading
from it", but there's no mention that resp.Body *must* be closed.

Am I mis-remembering something, or is
_, err := http.Get(url)

not supposed to leak connections?
Something has to be done with the data waiting to be sent to you on
the connection.
Calling .Close() on the Response.Body tells the http.Client to read
the data from the connection and discard it(or to close the connection
if the amount to read is too large)
I believe you have to actually read the entire body yourself -- with something like io.Copy + ioutil.Discard if
you don't care about it.
If you just call response.Body.Close() without reading till EOF, the conn is just closed and discarded (not reused).


You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 7 | next ›
Discussion Overview
groupgolang-nuts @
postedSep 16, '14 at 10:00p
activeSep 17, '14 at 7:28a



site design / logo © 2022 Grokbase