From 0cb2e80e0968afcc750436671b7e1f687de54875 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Fri, 29 May 2015 10:45:56 +0100 Subject: [PATCH] Proxy kills container and returns error when attach fails --- proxy/client.go | 4 ++-- proxy/start_container_interceptor.go | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/proxy/client.go b/proxy/client.go index 57cf98f4..87e1a968 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -35,7 +35,7 @@ func (c *client) ServeHTTP(w http.ResponseWriter, r *http.Request) { case err == docker.ErrNoSuchImage: http.Error(w, err.Error(), http.StatusNotFound) default: - http.Error(w, "Unable to intercept request", http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) Warning.Print("Error intercepting request: ", err) } return @@ -58,7 +58,7 @@ func (c *client) ServeHTTP(w http.ResponseWriter, r *http.Request) { } err = c.InterceptResponse(resp) if err != nil { - http.Error(w, "Unable to intercept response", http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) Warning.Print("Error intercepting response: ", err) return } diff --git a/proxy/start_container_interceptor.go b/proxy/start_container_interceptor.go index bce86074..1b95c733 100644 --- a/proxy/start_container_interceptor.go +++ b/proxy/start_container_interceptor.go @@ -1,6 +1,7 @@ package proxy import ( + "errors" "net/http" "strings" @@ -33,8 +34,10 @@ func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { args := []string{"attach"} args = append(args, cidrs...) args = append(args, container.ID) - if _, err := callWeave(args...); err != nil { - Warning.Printf("Attaching container %s to weave network failed: %v", container.ID, err) + if output, err := callWeave(args...); err != nil { + i.client.KillContainer(docker.KillContainerOptions{ID: container.ID}) + Warning.Printf("Attaching container %s to weave network failed: %s", container.ID, string(output)) + return errors.New(string(output)) } return nil }