Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2442)

Issue 7419050: code review 7419050: net/http: close TCP connection on Response.Body.Close (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 1 month ago by bradfitz
Modified:
11 years, 1 month ago
Reviewers:
CC:
golang-dev, adg
Visibility:
Public.

Description

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 issue 3672

Patch Set 1 #

Patch Set 2 : diff -r e39b9fa789ca https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r e39b9fa789ca https://go.googlecode.com/hg/ #

Total comments: 10

Patch Set 4 : diff -r 84a41a2c376b https://go.googlecode.com/hg/ #

Patch Set 5 : diff -r 91db139d15e5 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+98 lines, -52 lines) Patch
M src/pkg/net/http/response_test.go View 1 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/net/http/sniff_test.go View 1 4 chunks +10 lines, -1 line 0 comments Download
M src/pkg/net/http/transport.go View 1 2 3 9 chunks +23 lines, -50 lines 0 comments Download
M src/pkg/net/http/transport_test.go View 1 1 chunk +64 lines, -0 lines 0 comments Download

Messages

Total messages: 6
bradfitz
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 1 month ago (2013-03-04 23:04:52 UTC) #1
adg
It's definitely better, I don't know how much simpler it is though. The disembodied closure ...
11 years, 1 month ago (2013-03-05 06:44:28 UTC) #2
bradfitz
https://codereview.appspot.com/7419050/diff/4001/src/pkg/net/http/transport.go File src/pkg/net/http/transport.go (right): https://codereview.appspot.com/7419050/diff/4001/src/pkg/net/http/transport.go#newcode642 src/pkg/net/http/transport.go:642: waitForBodyRead = make(chan bool, 2) On 2013/03/05 06:44:28, adg ...
11 years, 1 month ago (2013-03-05 16:35:50 UTC) #3
bradfitz
Hello golang-dev@googlegroups.com, adg@golang.org (cc: golang-dev@googlegroups.com), Please take another look.
11 years, 1 month ago (2013-03-05 18:51:35 UTC) #4
adg
LGTM https://codereview.appspot.com/7419050/diff/4001/src/pkg/net/http/transport.go File src/pkg/net/http/transport.go (right): https://codereview.appspot.com/7419050/diff/4001/src/pkg/net/http/transport.go#newcode644 src/pkg/net/http/transport.go:644: waitForBodyRead <- false // don't reuse this connection ...
11 years, 1 month ago (2013-03-06 01:30:37 UTC) #5
bradfitz
11 years, 1 month ago (2013-03-06 02:47:23 UTC) #6
*** Submitted as https://code.google.com/p/go/source/detail?r=d4e1ec84876c ***

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 issue 3672

R=golang-dev, adg
CC=golang-dev
https://codereview.appspot.com/7419050
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b