mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #7744 from LK4D4/fix_race_cleanup_start_#6904
Fix race condition between cleanup and Start
This commit is contained in:
commit
c4a190db0c
1 changed files with 7 additions and 18 deletions
|
@ -101,15 +101,16 @@ func (m *containerMonitor) Start() error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
exitStatus int
|
exitStatus int
|
||||||
|
// this variable indicates where we in execution flow:
|
||||||
|
// before Run or after
|
||||||
|
afterRun bool
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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
|
// ensure that when the monitor finally exits we release the networking and unmount the rootfs
|
||||||
defer func() {
|
defer func() {
|
||||||
if !underLock {
|
if afterRun {
|
||||||
m.container.Lock()
|
m.container.Lock()
|
||||||
|
m.container.State.SetStopped(exitStatus)
|
||||||
defer m.container.Unlock()
|
defer m.container.Unlock()
|
||||||
}
|
}
|
||||||
m.Close()
|
m.Close()
|
||||||
|
@ -146,15 +147,13 @@ func (m *containerMonitor) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// here container.Lock is already lost
|
// here container.Lock is already lost
|
||||||
underLock = false
|
afterRun = true
|
||||||
|
|
||||||
m.resetMonitor(err == nil && exitStatus == 0)
|
m.resetMonitor(err == nil && exitStatus == 0)
|
||||||
|
|
||||||
if m.shouldRestart(exitStatus) {
|
if m.shouldRestart(exitStatus) {
|
||||||
m.container.State.SetRestarting(exitStatus)
|
m.container.State.SetRestarting(exitStatus)
|
||||||
|
|
||||||
m.container.LogEvent("die")
|
m.container.LogEvent("die")
|
||||||
|
|
||||||
m.resetContainer()
|
m.resetContainer()
|
||||||
|
|
||||||
// sleep with a small time increment between each restart to help avoid issues cased by quickly
|
// sleep with a small time increment between each restart to help avoid issues cased by quickly
|
||||||
|
@ -164,24 +163,14 @@ func (m *containerMonitor) Start() error {
|
||||||
// we need to check this before reentering the loop because the waitForNextRestart could have
|
// we need to check this before reentering the loop because the waitForNextRestart could have
|
||||||
// been terminated by a request from a user
|
// been terminated by a request from a user
|
||||||
if m.shouldStop {
|
if m.shouldStop {
|
||||||
m.container.State.SetStopped(exitStatus)
|
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
m.container.State.SetStopped(exitStatus)
|
|
||||||
|
|
||||||
m.container.LogEvent("die")
|
m.container.LogEvent("die")
|
||||||
|
|
||||||
m.resetContainer()
|
m.resetContainer()
|
||||||
|
return err
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// resetMonitor resets the stateful fields on the containerMonitor based on the
|
// resetMonitor resets the stateful fields on the containerMonitor based on the
|
||||||
|
|
Loading…
Add table
Reference in a new issue