Browse Source

Merge pull request #156 from matrix-org/kegan/httpcache-update

Update httpcache to fix memory leak
rxl881/google
Kegsay 8 years ago
committed by GitHub
parent
commit
eac024eabb
  1. 2
      vendor/manifest
  2. 12
      vendor/src/github.com/gregjones/httpcache/httpcache.go
  3. 5
      vendor/src/github.com/gregjones/httpcache/httpcache_test.go

2
vendor/manifest

@ -126,7 +126,7 @@
{ {
"importpath": "github.com/gregjones/httpcache", "importpath": "github.com/gregjones/httpcache",
"repository": "https://github.com/gregjones/httpcache", "repository": "https://github.com/gregjones/httpcache",
"revision": "413781778738c08fdbb98e1dd65f5abffe8832d0",
"revision": "d02018f006d98f58512bf3adfc171d88d17626df",
"branch": "master" "branch": "master"
}, },
{ {

12
vendor/src/github.com/gregjones/httpcache/httpcache.go

@ -223,22 +223,22 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
} }
if req2 != nil { if req2 != nil {
// Associate original request with cloned request so we can refer to // Associate original request with cloned request so we can refer to
// it in CancelRequest()
// it in CancelRequest(). Release the mapping when it's no longer needed.
t.setModReq(req, req2) t.setModReq(req, req2)
req = req2
defer func() {
defer func(originalReq *http.Request) {
// Release req/clone mapping on error // Release req/clone mapping on error
if err != nil { if err != nil {
t.setModReq(req, nil)
t.setModReq(originalReq, nil)
} }
if resp != nil { if resp != nil {
// Release req/clone mapping on body close/EOF // Release req/clone mapping on body close/EOF
resp.Body = &onEOFReader{ resp.Body = &onEOFReader{
rc: resp.Body, rc: resp.Body,
fn: func() { t.setModReq(req, nil) },
fn: func() { t.setModReq(originalReq, nil) },
} }
} }
}()
}(req)
req = req2
} }
} }
} }

5
vendor/src/github.com/gregjones/httpcache/httpcache_test.go

@ -465,6 +465,11 @@ func TestGetWithLastModified(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer func() {
if len(s.transport.modReq) != 0 {
t.Errorf("Request-map is not empty")
}
}()
{ {
resp, err := s.client.Do(req) resp, err := s.client.Do(req)
if err != nil { if err != nil {

Loading…
Cancel
Save