Fix race condition on exec

Signed-off-by: Pierre Wacrenier <pierre.wacrenier@gmail.com>
This commit is contained in:
Pierre Wacrenier 2015-02-05 01:08:18 +01:00
parent e87c276c1e
commit 16f5945439
2 changed files with 17 additions and 4 deletions

View File

@ -279,12 +279,17 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
return
}
if err := proxy(c.tlsConfig, container.Node.Addr, w, r); err != nil {
cb := func(resp *http.Response) {
if resp.StatusCode == http.StatusCreated {
log.Debugf("[REFRESH CONTAINER] --> %s", container.Id)
container.Node.RefreshContainer(container.Id, true)
}
}
if err := proxyAsync(c.tlsConfig, container.Node.Addr, w, r, cb); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
log.Debugf("[REFRESH CONTAINER] --> %s", container.Id)
container.Node.RefreshContainer(container.Id, true)
}
// Proxy a request to the right node

View File

@ -50,7 +50,7 @@ func copyHeader(dst, src http.Header) {
}
}
func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
func proxyAsync(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request, callback func(*http.Response)) error {
// Use a new client for each request
client, scheme := newClientAndScheme(tlsConfig)
// RequestURI may not be sent to client
@ -65,6 +65,10 @@ func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Re
return err
}
if callback != nil {
callback(resp)
}
copyHeader(w.Header(), resp.Header)
w.WriteHeader(resp.StatusCode)
io.Copy(NewWriteFlusher(w), resp.Body)
@ -73,6 +77,10 @@ func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Re
return nil
}
func proxy(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
return proxyAsync(tlsConfig, addr, w, r, nil)
}
func hijack(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request) error {
if parts := strings.SplitN(addr, "://", 2); len(parts) == 2 {
addr = parts[1]