mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
proxy: always cancel in-flight request
This fits the way for go1.5 to cancel request.
This commit is contained in:
parent
6fc638673c
commit
ece39c9462
@ -26,8 +26,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/coreos/etcd/etcdserver/etcdhttp/httptypes"
|
|
||||||
"time"
|
"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.
|
// 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
|
var requestClosed int32
|
||||||
completeCh := make(chan bool, 1)
|
completeCh := make(chan bool, 1)
|
||||||
closeNotifier, ok := rw.(http.CloseNotifier)
|
closeNotifier, ok := rw.(http.CloseNotifier)
|
||||||
|
cancel := httputil.RequestCanceler(p.transport, proxyreq)
|
||||||
if ok {
|
if ok {
|
||||||
go func() {
|
go func() {
|
||||||
select {
|
select {
|
||||||
case <-closeNotifier.CloseNotify():
|
case <-closeNotifier.CloseNotify():
|
||||||
atomic.StoreInt32(&requestClosed, 1)
|
atomic.StoreInt32(&requestClosed, 1)
|
||||||
log.Printf("proxy: client %v closed request prematurely", clientreq.RemoteAddr)
|
log.Printf("proxy: client %v closed request prematurely", clientreq.RemoteAddr)
|
||||||
|
cancel()
|
||||||
tp, ok := p.transport.(*http.Transport)
|
|
||||||
if ok {
|
|
||||||
tp.CancelRequest(proxyreq)
|
|
||||||
}
|
|
||||||
case <-completeCh:
|
case <-completeCh:
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user