Skip to content

Commit c0ecfb0

Browse files
committed
net/http: close client fd sooner on response read error
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
1 parent 847197d commit c0ecfb0

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/pkg/net/http/transport.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,9 @@ func (pc *persistConn) readLoop() {
535535
}
536536
resp, err := ReadResponse(pc.br, rc.req)
537537

538-
if err == nil {
538+
if err != nil {
539+
pc.close()
540+
} else {
539541
hasBody := rc.req.Method != "HEAD" && resp.ContentLength != 0
540542
if rc.addedGzip && hasBody && resp.Header.Get("Content-Encoding") == "gzip" {
541543
resp.Header.Del("Content-Encoding")

0 commit comments

Comments
 (0)