moby/integration
Sebastiaan van Stijn aeb8972281
daemon: daemon.containerRestart: don't cancel restart on context cancel
commit def549c8f6 passed through the context
to the daemon.ContainerStart function. As a result, restarting containers
no longer is an atomic operation, because a context cancellation could
interrupt the restart (between "stopping" and "(re)starting"), resulting
in the container being stopped, but not restarted.

Restarting a container, or more factually; making a successful request on
the `/containers/{id]/restart` endpoint, should be an atomic operation.

This patch uses a context.WithoutCancel for restart requests.

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).

Before this patch, starting a container that bind-mounts the docker socket,
then restarting itself from within the container would cancel the restart
operation. The container would be stopped, but not started after that:

    docker run -dit --name myself -v /var/run/docker.sock:/var/run/docker.sock docker:cli sh
    docker exec myself sh -c 'docker restart myself'

    docker ps -a
    CONTAINER ID   IMAGE         COMMAND                  CREATED          STATUS                       PORTS     NAMES
    3a2a741c65ff   docker:cli    "docker-entrypoint.s…"   26 seconds ago   Exited (128) 7 seconds ago             myself

With this patch: the stop still cancels the exec, but does not cancel the
restart operation, and the container is started again:

    docker run -dit --name myself -v /var/run/docker.sock:/var/run/docker.sock docker:cli sh
    docker exec myself sh -c 'docker restart myself'
    docker ps
    CONTAINER ID   IMAGE        COMMAND                  CREATED              STATUS         PORTS     NAMES
    4393a01f7c75   docker:cli   "docker-entrypoint.s…"   About a minute ago   Up 4 seconds             myself

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-24 12:56:45 +02:00
..
build api/types: move ContainerLogsOptions to api/types/container 2023-10-12 11:30:12 +02:00
capabilities api/types: move ContainerLogsOptions to api/types/container 2023-10-12 11:30:12 +02:00
config Don't run tests twice 2023-09-19 11:37:55 +02:00
container daemon: daemon.containerRestart: don't cancel restart on context cancel 2023-10-24 12:56:45 +02:00
daemon api/types: move ContainerLogsOptions to api/types/container 2023-10-12 11:30:12 +02:00
distribution bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
image c8d integration: skip TestImportWithCustomPlatform 2023-10-16 18:08:36 +01:00
internal api/types: move ContainerStartOptions to api/types/container 2023-10-12 11:29:24 +02:00
network api/types: move ContainerRemoveOptions to api/types/container 2023-10-12 11:29:23 +02:00
plugin api/types: move ContainerLogsOptions to api/types/container 2023-10-12 11:30:12 +02:00
secret Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
service api/types: move ContainerLogsOptions to api/types/container 2023-10-12 11:30:12 +02:00
session Wire up tests to support otel tracing 2023-09-07 18:38:22 +00:00
system Fix disk usage test 2023-10-18 21:20:54 -07:00
testdata/https Update test certificates 2021-05-18 09:43:21 +02:00
volume api/types: move ContainerRemoveOptions to api/types/container 2023-10-12 11:29:23 +02:00
doc.go Add canonical import comment 2018-02-05 16:51:57 -05:00