Fix race between container cleanup and inspect/ps

Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com>
Upstream-commit: 93d6adf8a19855edf118d27d0239222f572d8292
Component: engine
This commit is contained in:
Alexandr Morozov
2014-08-14 15:51:31 +04:00
parent f4db7d15dc
commit 1b8bad68b3

View File

@ -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) {