mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: containerStop: fix ordering of "stop" and "die" events
Commit8e6cd44ce4added synchronisation to wait for the container's status to be updated in memory. However, since952902efbc, a defer was used to produce the container's "stop" event. As a result of the sychronisation that was added, the "die" event would now be produced before the "stop" event. This patch moves the locking inside the defer to restore the previous behavior. Unfortunately the order of events is still not guaranteed, because events are emited from multiple goroutines that don't have synchronisation between them; this is something to look at for follow ups. This patch keeps the status quo and should preserve the old behavior, which was "more" correct in most cases. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -74,6 +74,9 @@ func (daemon *Daemon) containerStop(ctx context.Context, ctr *container.Containe
|
||||
defer func() {
|
||||
if retErr == nil {
|
||||
daemon.LogContainerEvent(ctr, events.ActionStop)
|
||||
// Ensure container status changes are committed by handler of container exit before returning control to the caller
|
||||
ctr.Lock()
|
||||
defer ctr.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -93,9 +96,6 @@ func (daemon *Daemon) containerStop(ctx context.Context, ctr *container.Containe
|
||||
defer cancel()
|
||||
|
||||
if status := <-ctr.Wait(subCtx, containertypes.WaitConditionNotRunning); status.Err() == nil {
|
||||
// Ensure container status changes are committed by handler of container exit before returning control to the caller
|
||||
ctr.Lock()
|
||||
defer ctr.Unlock()
|
||||
// container did exit, so ignore any previous errors and return
|
||||
return nil
|
||||
}
|
||||
@@ -125,9 +125,5 @@ func (daemon *Daemon) containerStop(ctx context.Context, ctr *container.Containe
|
||||
// container did exit, so ignore previous errors and continue
|
||||
}
|
||||
|
||||
// Ensure container status changes are committed by handler of container exit before returning control to the caller
|
||||
ctr.Lock()
|
||||
defer ctr.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user