Commit b2e9f425 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: fix crash with Transport.CloseIdleConnections

Thanks Michael Lore for the bug report!

Fixes #3266

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5754068
parent 98cfe677
......@@ -196,7 +196,7 @@ func (t *Transport) CloseIdleConnections() {
pconn.close()
}
}
t.idleConn = nil
t.idleConn = make(map[string][]*persistConn)
}
//
......
......@@ -698,6 +698,32 @@ func TestTransportPersistConnLeak(t *testing.T) {
}
}
// This used to crash; http://golang.org/issue/3266
func TestTransportIdleConnCrash(t *testing.T) {
tr := &Transport{}
c := &Client{Transport: tr}
unblockCh := make(chan bool, 1)
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
<-unblockCh
tr.CloseIdleConnections()
}))
defer ts.Close()
didreq := make(chan bool)
go func() {
res, err := c.Get(ts.URL)
if err != nil {
t.Error(err)
} else {
res.Body.Close() // returns idle conn
}
didreq <- true
}()
unblockCh <- true
<-didreq
}
type fooProto struct{}
func (fooProto) RoundTrip(req *Request) (*Response, error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment