diff --git a/api/handlers.go b/api/handlers.go index f95937e209..288f988173 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -545,12 +545,14 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re r.URL.Path = strings.Replace(r.URL.Path, name, container.Id, 1) } - if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil { - httpError(w, err.Error(), http.StatusInternalServerError) + cb := func(resp *http.Response) { + // force fresh container + container.Refresh() } - // force fresh container - container.Refresh() + if err := proxyAsync(c.tlsConfig, container.Engine.Addr, w, r, cb); err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + } } // Proxy a request to the right node diff --git a/api/utils.go b/api/utils.go index 8041616c80..f5877f8979 100644 --- a/api/utils.go +++ b/api/utils.go @@ -81,14 +81,14 @@ func proxyAsync(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *ht w.WriteHeader(resp.StatusCode) io.Copy(NewWriteFlusher(w), resp.Body) - // cleanup - resp.Body.Close() - closeIdleConnections(client) - if callback != nil { callback(resp) } + // cleanup + resp.Body.Close() + closeIdleConnections(client) + return nil }