proxy: handle canceled proxy request gracefully

when a client of the proxy server cancels a request the proxy should not
set the endpoint state to unavailable
release-2.1
Wolfgang Ebner 2015-06-16 20:39:42 +02:00
parent 0ef53ee500
commit 864ce5f946
1 changed files with 6 additions and 0 deletions

View File

@ -90,6 +90,7 @@ func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request
return
}
requestCanceled := false
completeCh := make(chan bool, 1)
closeNotifier, ok := rw.(http.CloseNotifier)
if ok {
@ -98,6 +99,8 @@ func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request
case <-closeNotifier.CloseNotify():
tp, ok := p.transport.(*http.Transport)
if ok {
requestCanceled = true
log.Printf("proxy: request from %v canceled", clientreq.RemoteAddr)
tp.CancelRequest(proxyreq)
}
case <-completeCh:
@ -118,6 +121,9 @@ func (p *reverseProxy) ServeHTTP(rw http.ResponseWriter, clientreq *http.Request
redirectRequest(proxyreq, ep.URL)
res, err = p.transport.RoundTrip(proxyreq)
if requestCanceled {
return
}
if err != nil {
log.Printf("proxy: failed to direct request to %s: %v", ep.URL.String(), err)
ep.Failed()