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

net/http: document that closing a http.Response.Body without first reading it closes the connection #6700

Closed
schmichael opened this issue Oct 31, 2013 · 6 comments

Comments

@schmichael
Copy link
Contributor

tl;dr - summarize http://golang.org/src/pkg/net/http/transport.go#L942 in the
http.Response.Body docs: http://tip.golang.org/pkg/net/http/#Response

Perhaps: "Calling Body.Close() before reading the entire response will cause the
underlying connection to be closed."

What steps will reproduce the problem?

http://play.golang.org/p/ue3kwSEb37 (Requires net/http.Get so you have to copy it
locally)

What is the expected output?

Output is as expected once you understand the importance of reading the Response.Body
before closing it.

What do you see instead?

"cannot assign requested address" due to ephemeral port exhaustion.

Which operating system are you using?

Linux / Ubuntu 13.10

Which version are you using?  (run 'go version')

1.1.1
@bradfitz
Copy link
Contributor

Comment 1:

I'm not sure what we would say or want to guarantee here.
Any wording I can think of sounds too low-level or locks us into a certain behavior
forever.

Status changed to Thinking.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-main.

@gopherbot
Copy link

Comment 5 by julien.laffaye:

Shouldnt Body.Close() call io.Copy with ioutil.Discard, if the internals of http package
require it ?

@bradfitz
Copy link
Contributor

Comment 6:

It used to do that, but that was more problematic. There might be a multi-GB post body
coming. In that case it's better to close the connection.
In any case, this is all a detail that the user shouldn't care about. In HTTP/2 it's
totally different too. Documenting anything in particular seems misleading.

Status changed to WontFix.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants