From 6c03aa317404703a300ef25c3b5dc18d8e9cc64c Mon Sep 17 00:00:00 2001 From: Kenfe-Mickael Laventure Date: Wed, 15 Nov 2017 19:19:26 -0800 Subject: [PATCH] Add missing lock in ProcessEvent Signed-off-by: Kenfe-Mickael Laventure --- daemon/monitor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/daemon/monitor.go b/daemon/monitor.go index c0a265dac5..26af8696e0 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -46,12 +46,12 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc daemon.LogContainerEvent(c, "oom") case libcontainerd.EventExit: if int(ei.Pid) == c.Pid { + c.Lock() _, _, err := daemon.containerd.DeleteTask(context.Background(), c.ID) if err != nil { logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID) } - c.Lock() c.StreamConfig.Wait() c.Reset(false) @@ -68,6 +68,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc c.SetStopped(&exitStatus) defer daemon.autoRemove(c) } + defer c.Unlock() // needs to be called before autoRemove // cancel healthcheck here, they will be automatically // restarted if/when the container is started again @@ -91,7 +92,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc } } if err != nil { + c.Lock() c.SetStopped(&exitStatus) + c.Unlock() defer daemon.autoRemove(c) if err != restartmanager.ErrRestartCanceled { logrus.Errorf("restartmanger wait error: %+v", err) @@ -101,7 +104,6 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc } daemon.setStateCounter(c) - defer c.Unlock() if err := c.CheckpointTo(daemon.containersReplica); err != nil { return err }