mirror of
https://github.com/golang/go
synced 2024-11-22 05:34:39 -07:00
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
This commit is contained in:
parent
98cfe6770d
commit
b2e9f425b9
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user