]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: close client fd sooner on response read error
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 31 Jan 2012 17:45:13 +0000 (09:45 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 31 Jan 2012 17:45:13 +0000 (09:45 -0800)
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

src/pkg/net/http/transport.go

index 4de070f01f10d806c71db938b6d2a6ee80ed6b2b..693215edd4fcbce040a10b517a29e1dc4b58bc20 100644 (file)
@@ -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")