mirror of https://github.com/docker/docs.git
Merge pull request #17220 from calavera/fix_double_removal
Do not fail when a container is being removed and we request its delete again.
This commit is contained in:
commit
70af70aa0b
|
@ -76,22 +76,20 @@ func (daemon *Daemon) rm(container *Container, forceRemove bool) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Container state RemovalInProgress should be used to avoid races.
|
||||||
|
if err = container.setRemovalInProgress(); err != nil {
|
||||||
|
if err == derr.ErrorCodeAlreadyRemoving {
|
||||||
|
// do not fail when the removal is in progress started by other request.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return derr.ErrorCodeRmState.WithArgs(err)
|
||||||
|
}
|
||||||
|
defer container.resetRemovalInProgress()
|
||||||
|
|
||||||
// stop collection of stats for the container regardless
|
// stop collection of stats for the container regardless
|
||||||
// if stats are currently getting collected.
|
// if stats are currently getting collected.
|
||||||
daemon.statsCollector.stopCollection(container)
|
daemon.statsCollector.stopCollection(container)
|
||||||
|
|
||||||
element := daemon.containers.Get(container.ID)
|
|
||||||
if element == nil {
|
|
||||||
return derr.ErrorCodeRmNotFound.WithArgs(container.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Container state RemovalInProgress should be used to avoid races.
|
|
||||||
if err = container.setRemovalInProgress(); err != nil {
|
|
||||||
return derr.ErrorCodeRmState.WithArgs(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
defer container.resetRemovalInProgress()
|
|
||||||
|
|
||||||
if err = container.Stop(3); err != nil {
|
if err = container.Stop(3); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package daemon
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/runconfig"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestContainerDoubleDelete(t *testing.T) {
|
||||||
|
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmp)
|
||||||
|
daemon := &Daemon{
|
||||||
|
repository: tmp,
|
||||||
|
root: tmp,
|
||||||
|
}
|
||||||
|
|
||||||
|
container := &Container{
|
||||||
|
CommonContainer: CommonContainer{
|
||||||
|
State: NewState(),
|
||||||
|
Config: &runconfig.Config{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mark the container as having a delete in progress
|
||||||
|
if err := container.setRemovalInProgress(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to remove the container when it's start is removalInProgress.
|
||||||
|
// It should ignore the container and not return an error.
|
||||||
|
if err := daemon.rm(container, true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue