From bc9db72212606fc385d1533ab58f4712aa6c488f Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Tue, 20 Oct 2015 11:47:02 +0100 Subject: [PATCH] [proxy] Add notifyWaiters to fix anticipated race condition. * User makes /start request, and blocks on the waiter * ContainerStarted fires with ID * Container goes away * We try to inspect the container to get the entrypoint, which fails * Previously, this wouldn't call notifyWaiters and the /start would hang (I expect) --- proxy/proxy.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 7b88f745..dc6bcfcf 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -297,19 +297,17 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) { // weavedocker.ContainerObserver interface func (proxy *Proxy) ContainerStarted(ident string) { container, err := proxy.client.InspectContainer(ident) - if err != nil { - if _, ok := err.(*docker.NoSuchContainer); !ok { - Log.Warningf("unable to attach new container %s since inspecting it failed: %v", ident, err) + if err == nil { + if containerShouldAttach(container) { + err = proxy.attach(container, true) + } else if containerIsWeaveRouter(container) { + err = proxy.attachRouter(container) } - return } - // If this was a container we modified the entrypoint for, attach it to the network - if containerShouldAttach(container) { - err = proxy.attach(container, true) - } else if containerIsWeaveRouter(container) { - err = proxy.attachRouter(container) + if _, ok := err.(*docker.NoSuchContainer); err != nil && !ok { + Log.Warningf("unable to attach new container %s since inspecting it failed: %v", ident, err) } - proxy.notifyWaiters(container.ID, err) + proxy.notifyWaiters(ident, err) } func containerShouldAttach(container *docker.Container) bool {