Not use goroutine for container's auto-removal
Before this, container's auto-removal after exit is done in a goroutine, this commit will get ContainerRm out of the goroutine. Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
This commit is contained in:
parent
6dd8e10d6e
commit
1537dbe2d6
2 changed files with 17 additions and 6 deletions
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/docker/docker/daemon/exec"
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/engine-api/types"
|
||||
)
|
||||
|
||||
// StateChanged updates daemon state changes from containerd
|
||||
|
@ -29,6 +30,14 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
|
|||
daemon.updateHealthMonitor(c)
|
||||
daemon.LogContainerEvent(c, "oom")
|
||||
case libcontainerd.StateExit:
|
||||
// if containers AutoRemove flag is set, remove it after clean up
|
||||
if c.HostConfig.AutoRemove {
|
||||
defer func() {
|
||||
if err := daemon.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil {
|
||||
logrus.Errorf("can't remove container %s: %v", c.ID, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
c.Wait()
|
||||
|
|
|
@ -113,6 +113,14 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
|
|||
}
|
||||
container.ToDisk()
|
||||
daemon.Cleanup(container)
|
||||
// if containers AutoRemove flag is set, remove it after clean up
|
||||
if container.HostConfig.AutoRemove {
|
||||
container.Unlock()
|
||||
if err := daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true}); err != nil {
|
||||
logrus.Errorf("can't remove container %s: %v", container.ID, err)
|
||||
}
|
||||
container.Lock()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
@ -198,10 +206,4 @@ func (daemon *Daemon) Cleanup(container *container.Container) {
|
|||
}
|
||||
}
|
||||
container.CancelAttachContext()
|
||||
|
||||
// if containers AutoRemove flag is set, remove it after clean up
|
||||
if container.HostConfig.AutoRemove {
|
||||
// If containers lock is not released, goroutine will guarantee no block
|
||||
go daemon.ContainerRm(container.ID, &types.ContainerRmConfig{ForceRemove: true, RemoveVolume: true})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue