From 93d6adf8a19855edf118d27d0239222f572d8292 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Thu, 14 Aug 2014 15:51:31 +0400 Subject: [PATCH] Fix race between container cleanup and inspect/ps Signed-off-by: Alexandr Morozov --- daemon/monitor.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/daemon/monitor.go b/daemon/monitor.go index e0fdece14e..e8940db24c 100644 --- a/daemon/monitor.go +++ b/daemon/monitor.go @@ -103,8 +103,17 @@ func (m *containerMonitor) Start() error { exitStatus int ) + // this variable indicates that we under container.Lock + underLock := true + // ensure that when the monitor finally exits we release the networking and unmount the rootfs - defer m.Close() + defer func() { + if !underLock { + m.container.Lock() + defer m.container.Unlock() + } + m.Close() + }() // reset the restart count m.container.RestartCount = -1 @@ -136,6 +145,9 @@ func (m *containerMonitor) Start() error { log.Errorf("Error running container: %s", err) } + // here container.Lock is already lost + underLock = false + m.resetMonitor(err == nil && exitStatus == 0) if m.shouldRestart(exitStatus) {