daemon: daemon.shutdownContainer: use context.WithoutCancel
Use context.WithoutCancel so that both the containerStop and container.Wait can share the same parent context. This context is still a "TODO", but can be wired up in future. It's worth noting that daemon.containerStop already uses context.WithoutCancel, so in that function, we'll be wrapping the context twice, but this should likely not cause issues (just redundant for this code-path). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
dca89c67ef
commit
aad51c0b4e
1 changed files with 5 additions and 2 deletions
|
@ -48,6 +48,7 @@ import (
|
||||||
"github.com/docker/docker/dockerversion"
|
"github.com/docker/docker/dockerversion"
|
||||||
"github.com/docker/docker/errdefs"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/docker/docker/image"
|
"github.com/docker/docker/image"
|
||||||
|
"github.com/docker/docker/internal/compatcontext"
|
||||||
"github.com/docker/docker/layer"
|
"github.com/docker/docker/layer"
|
||||||
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
|
||||||
"github.com/docker/docker/libnetwork"
|
"github.com/docker/docker/libnetwork"
|
||||||
|
@ -1212,14 +1213,16 @@ func (daemon *Daemon) waitForStartupDone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) shutdownContainer(c *container.Container) error {
|
func (daemon *Daemon) shutdownContainer(c *container.Container) error {
|
||||||
|
ctx := compatcontext.WithoutCancel(context.TODO())
|
||||||
|
|
||||||
// If container failed to exit in stopTimeout seconds of SIGTERM, then using the force
|
// If container failed to exit in stopTimeout seconds of SIGTERM, then using the force
|
||||||
if err := daemon.containerStop(context.TODO(), c, containertypes.StopOptions{}); err != nil {
|
if err := daemon.containerStop(ctx, c, containertypes.StopOptions{}); err != nil {
|
||||||
return fmt.Errorf("Failed to stop container %s with error: %v", c.ID, err)
|
return fmt.Errorf("Failed to stop container %s with error: %v", c.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait without timeout for the container to exit.
|
// Wait without timeout for the container to exit.
|
||||||
// Ignore the result.
|
// Ignore the result.
|
||||||
<-c.Wait(context.Background(), container.WaitConditionNotRunning)
|
<-c.Wait(ctx, container.WaitConditionNotRunning)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue