Merge pull request #369 from mota/fix-exec

Fix race condition on exec
This commit is contained in:
Victor Vieux 2015-02-04 17:35:35 -08:00
commit 4ea8159735
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]