From 78c86372c8574fa7c223d3ff512d1f4eac3c8f17 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Fri, 13 Nov 2015 12:02:18 +0000 Subject: [PATCH] Maintain container-by-pid index correctly. --- probe/docker/registry.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/probe/docker/registry.go b/probe/docker/registry.go index e8ad506ef..66e63b596 100644 --- a/probe/docker/registry.go +++ b/probe/docker/registry.go @@ -252,11 +252,17 @@ func (r *registry) updateContainerState(containerID string) { if !ok { c = NewContainerStub(dockerContainer) r.containers[containerID] = c - r.containersByPID[dockerContainer.State.Pid] = c } else { + // potentially remove existing pid mapping. + delete(r.containersByPID, c.PID()) c.UpdateState(dockerContainer) } + // Update PID index + if c.PID() > 1 { + r.containersByPID[c.PID()] = c + } + // Trigger anyone watching for updates for _, f := range r.watchers { f(c)