Skip to content

Commit

Permalink
net/http: close client fd sooner on response read error
Browse files Browse the repository at this point in the history
This fixes some test noise in TestStressSurpriseServerCloses when
ulimit -n something low, like 256 on a Mac.

Previously, when the server closed on us and we were expecting more
responses (like we are in that test), we'd read an "Unexpected EOF"
and just forget about the client's net.Conn.  Now it's closed,
rather than waiting on the finalizer to release the fd.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5602043
  • Loading branch information
bradfitz committed Jan 31, 2012
1 parent 847197d commit c0ecfb0
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pkg/net/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,9 @@ func (pc *persistConn) readLoop() {
}
resp, err := ReadResponse(pc.br, rc.req)

if err == nil {
if err != nil {
pc.close()
} else {
hasBody := rc.req.Method != "HEAD" && resp.ContentLength != 0
if rc.addedGzip && hasBody && resp.Header.Get("Content-Encoding") == "gzip" {
resp.Header.Del("Content-Encoding")
Expand Down

0 comments on commit c0ecfb0

Please sign in to comment.