From dca89c67efb2ea4cede643646b50bc73c2b1cd54 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 20 Oct 2023 17:44:30 +0200 Subject: [PATCH] daemon: daemon.containerStop: use context.WithoutCancel Follow-up to fc94ed0a86dbac35f9e4cbdd778ead7bc2d53bf9. Now that f6e44bc0e82572885b5cfac3d2f67c583d657a07 added the compatcontext package, we can start using context.WithoutCancel. Signed-off-by: Sebastiaan van Stijn --- daemon/stop.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/daemon/stop.go b/daemon/stop.go index 93d975a3c8..3be13d80fb 100644 --- a/daemon/stop.go +++ b/daemon/stop.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/api/types/events" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" + "github.com/docker/docker/internal/compatcontext" "github.com/moby/sys/signal" "github.com/pkg/errors" ) @@ -41,13 +42,12 @@ func (daemon *Daemon) ContainerStop(ctx context.Context, name string, options co return nil } -// containerStop sends a stop signal, waits, sends a kill signal. -func (daemon *Daemon) containerStop(_ context.Context, ctr *container.Container, options containertypes.StopOptions) (retErr error) { - // Deliberately using a local context here, because cancelling the - // request should not cancel the stop. - // - // TODO(thaJeztah): pass context, and use context.WithoutCancel() once available: https://github.com/golang/go/issues/40221 - ctx := context.Background() +// containerStop sends a stop signal, waits, sends a kill signal. It uses +// a [context.WithoutCancel], so cancelling the context does not cancel +// the request to stop the container. +func (daemon *Daemon) containerStop(ctx context.Context, ctr *container.Container, options containertypes.StopOptions) (retErr error) { + // Cancelling the request should not cancel the stop. + ctx = compatcontext.WithoutCancel(ctx) if !ctr.IsRunning() { return nil