From ae4b4109b21c341cbe1b128c20479f5e7e50bffc Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sun, 14 Aug 2016 14:35:50 -0700 Subject: [PATCH 1/3] pkg/httputil: simplify RequestCanceler args --- pkg/httputil/httputil.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/httputil/httputil.go b/pkg/httputil/httputil.go index daf43bd8f..859fc9d49 100644 --- a/pkg/httputil/httputil.go +++ b/pkg/httputil/httputil.go @@ -13,7 +13,7 @@ import ( "net/http" ) -func RequestCanceler(rt http.RoundTripper, req *http.Request) func() { +func RequestCanceler(req *http.Request) func() { ch := make(chan struct{}) req.Cancel = ch From 0503676bde0804c0b67168ed361f566f9db58628 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sun, 14 Aug 2016 14:36:51 -0700 Subject: [PATCH 2/3] rafthttp: fix httputil.RequestCanceler --- rafthttp/pipeline.go | 2 +- rafthttp/snapshot_sender.go | 2 +- rafthttp/stream.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rafthttp/pipeline.go b/rafthttp/pipeline.go index 4774c91b8..1f07f3e49 100644 --- a/rafthttp/pipeline.go +++ b/rafthttp/pipeline.go @@ -117,7 +117,7 @@ func (p *pipeline) post(data []byte) (err error) { req := createPostRequest(u, RaftPrefix, bytes.NewBuffer(data), "application/protobuf", p.tr.URLs, p.tr.ID, p.tr.ClusterID) done := make(chan struct{}, 1) - cancel := httputil.RequestCanceler(p.tr.pipelineRt, req) + cancel := httputil.RequestCanceler(req) go func() { select { case <-done: diff --git a/rafthttp/snapshot_sender.go b/rafthttp/snapshot_sender.go index d0c6c866d..3d73ac809 100644 --- a/rafthttp/snapshot_sender.go +++ b/rafthttp/snapshot_sender.go @@ -103,7 +103,7 @@ func (s *snapshotSender) send(merged snap.Message) { // post posts the given request. // It returns nil when request is sent out and processed successfully. func (s *snapshotSender) post(req *http.Request) (err error) { - cancel := httputil.RequestCanceler(s.tr.pipelineRt, req) + cancel := httputil.RequestCanceler(req) type responseAndError struct { resp *http.Response diff --git a/rafthttp/stream.go b/rafthttp/stream.go index 8f17bd97b..241797f4d 100644 --- a/rafthttp/stream.go +++ b/rafthttp/stream.go @@ -413,7 +413,7 @@ func (cr *streamReader) dial(t streamType) (io.ReadCloser, error) { return nil, fmt.Errorf("stream reader is stopped") default: } - cr.cancel = httputil.RequestCanceler(cr.tr.streamRt, req) + cr.cancel = httputil.RequestCanceler(req) cr.mu.Unlock() resp, err := cr.tr.streamRt.RoundTrip(req) From f14fd43548f1c96fc8dc1ec331bc88ca384812ff Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sun, 14 Aug 2016 14:37:08 -0700 Subject: [PATCH 3/3] proxy/httpproxy: fix httputil.RequestCanceler --- proxy/httpproxy/reverse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy/httpproxy/reverse.go b/proxy/httpproxy/reverse.go index 64d082445..6ecf449f5 100644 --- a/proxy/httpproxy/reverse.go +++ b/proxy/httpproxy/reverse.go @@ -110,7 +110,7 @@ func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request var requestClosed int32 completeCh := make(chan bool, 1) closeNotifier, ok := rw.(http.CloseNotifier) - cancel := httputil.RequestCanceler(p.transport, proxyreq) + cancel := httputil.RequestCanceler(proxyreq) if ok { closeCh := closeNotifier.CloseNotify() go func() {