]> Cypherpunks repositories - gostls13.git/commit
net/http: close TCP connection on Response.Body.Close
authorBrad Fitzpatrick <bradfitz@golang.org>
Wed, 6 Mar 2013 02:47:27 +0000 (18:47 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 6 Mar 2013 02:47:27 +0000 (18:47 -0800)
commitce8341554caa8be64aeafd9bf2077a98db462fda
tree84b910423b69c032854db7bea98ad4f6edd5f5a2
parent0d9bf2757e71e64938b02c397d1d6e5666c5a213
net/http: close TCP connection on Response.Body.Close

Previously the HTTP client's (*Response).Body.Close would try
to keep reading until EOF, hoping to reuse the keep-alive HTTP
connection, but the EOF might never come, or it might take a
long time. Now we immediately close the TCP connection if we
haven't seen EOF.

This shifts the burden onto clients to read their whole response
bodies if they want the advantage of reusing TCP connections.

In the future maybe we could decide on heuristics to read some
number of bytes for some max amount of time before forcefully
closing, but I'd rather not for now.

Statistically, touching this code makes things regress, so I
wouldn't be surprised if this introduces new bugs, but all the
tests pass, and I think the code is simpler now too. Maybe.

Please test your HTTP client code before Go 1.1.

Fixes #3672

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7419050
src/pkg/net/http/response_test.go
src/pkg/net/http/sniff_test.go
src/pkg/net/http/transport.go
src/pkg/net/http/transport_test.go