proxy: websocket proxy exits immediately if backend is shutdown (#1869)

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw
2017-09-23 08:10:48 +08:00
committed by Matt Holt
parent 84a2f8e89e
commit e377eeff50
2 changed files with 47 additions and 2 deletions
+13 -2
View File
@@ -320,8 +320,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
}
defer backendConn.Close()
proxyDone := make(chan struct{}, 2)
// Proxy backend -> frontend.
go pooledIoCopy(conn, backendConn)
go func() {
pooledIoCopy(conn, backendConn)
proxyDone <- struct{}{}
}()
// Proxy frontend -> backend.
//
@@ -336,7 +341,13 @@ func (rp *ReverseProxy) ServeHTTP(rw http.ResponseWriter, outreq *http.Request,
backendConn.Write(rbuf)
}
}
pooledIoCopy(backendConn, conn)
go func() {
pooledIoCopy(backendConn, conn)
proxyDone <- struct{}{}
}()
// If one side is done, we are done.
<-proxyDone
} else {
// NOTE:
// Closing the Body involves acquiring a mutex, which is a