From df0d8b78922007a34d2bff444ada9e3025da2a6a Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 20 Nov 2020 19:25:19 +0200 Subject: [PATCH 1/2] #187 "created" action is handled separately in watchEvents() --- connector/docker.go | 1 - 1 file changed, 1 deletion(-) diff --git a/connector/docker.go b/connector/docker.go index 4a39bf9..ec0e6e0 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -15,7 +15,6 @@ import ( func init() { enabled["docker"] = NewDocker } var actionToStatus = map[string]string{ - "create": "created", "start": "running", "die": "exited", "stop": "exited", From 65e9c6dff6a4ac5922c5c18e4aba13142a802efa Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 20 Nov 2020 19:44:09 +0200 Subject: [PATCH 2/2] docker connector: refresh() delete container only if it not found but keep on failures If inspect() call was failed due to connection problems then container will be removed anyway as like ot wasn't found. This is probably almost never happens in real life but still some missed logic bug --- connector/docker.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/connector/docker.go b/connector/docker.go index ec0e6e0..063392f 100644 --- a/connector/docker.go +++ b/connector/docker.go @@ -160,9 +160,12 @@ func ipsFormat(networks map[string]api.ContainerNetwork) string { } func (cm *Docker) refresh(c *container.Container) { - insp := cm.inspect(c.Id) + insp, found, failed := cm.inspect(c.Id) + if failed { + return + } // remove container if no longer exists - if insp == nil { + if !found { cm.delByID(c.Id) return } @@ -178,14 +181,17 @@ func (cm *Docker) refresh(c *container.Container) { c.SetState(insp.State.Status) } -func (cm *Docker) inspect(id string) *api.Container { +func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bool) { c, err := cm.client.InspectContainer(id) if err != nil { - if _, ok := err.(*api.NoSuchContainer); !ok { - log.Errorf("%s (%T)", err.Error(), err) + if _, notFound := err.(*api.NoSuchContainer); notFound { + return c, false, false } + // other error e.g. connection failed + log.Errorf("%s (%T)", err.Error(), err) + return c, false, true } - return c + return c, true, false } // Mark all container IDs for refresh