proxy: always cancel in-flight request

This fits the way for go1.5 to cancel request.
This commit is contained in:
Yicheng Qin 2015-08-24 10:51:17 -07:00
parent 6fc638673c
commit ece39c9462

View File

@ -26,8 +26,10 @@ import (
"strings"
"sync/atomic"
"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
"time"
"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
"github.com/coreos/etcd/pkg/httputil"
)
// Hop-by-hop headers. These are removed when sent to the backend.
@ -98,17 +100,14 @@ 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)
if ok {
go func() {
select {
case <-closeNotifier.CloseNotify():
atomic.StoreInt32(&requestClosed, 1)
log.Printf("proxy: client %v closed request prematurely", clientreq.RemoteAddr)
tp, ok := p.transport.(*http.Transport)
if ok {
tp.CancelRequest(proxyreq)
}
cancel()
case <-completeCh:
}
}()