1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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:
Zhang Wei 2016-08-03 10:11:01 +08:00
parent 6dd8e10d6e
commit 1537dbe2d6
2 changed files with 17 additions and 6 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/daemon/exec" "github.com/docker/docker/daemon/exec"
"github.com/docker/docker/libcontainerd" "github.com/docker/docker/libcontainerd"
"github.com/docker/docker/runconfig" "github.com/docker/docker/runconfig"
"github.com/docker/engine-api/types"
) )
// StateChanged updates daemon state changes from containerd // 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.updateHealthMonitor(c)
daemon.LogContainerEvent(c, "oom") daemon.LogContainerEvent(c, "oom")
case libcontainerd.StateExit: 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() c.Lock()
defer c.Unlock() defer c.Unlock()
c.Wait() c.Wait()

View file

@ -113,6 +113,14 @@ func (daemon *Daemon) containerStart(container *container.Container) (err error)
} }
container.ToDisk() container.ToDisk()
daemon.Cleanup(container) 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() 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})
}
} }