moby/integration/container
Sebastiaan van Stijn 05d7386665
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>
(cherry picked from commit aeb8972281)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-24 16:29:20 +02:00
..
attach_test.go Make it explicit raw|multiplexed stream implementation being used 2022-05-12 11:36:31 +02:00
checkpoint_test.go integration(-cli): remove some redundant formatting 2022-10-08 17:41:39 +02:00
container_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
copy_test.go run getent with a noop stdin 2023-06-14 13:12:00 +02:00
create_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
daemon_linux_test.go integration: disable iptables in parallel tests 2023-07-07 15:43:08 -04:00
daemon_test.go integration: disable iptables in parallel tests 2023-07-07 15:43:08 -04:00
devices_windows_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
diff_test.go api/types/container: create type for changes endpoint 2023-05-03 21:23:42 +02:00
exec_linux_test.go container/exec: Support ConsoleSize 2022-06-24 11:54:25 +02:00
exec_test.go refactor: move from io/ioutil to io and os package 2021-08-27 14:56:57 +08:00
export_test.go Using test names instead of hardcoded ones in integration/container directory 2020-05-18 16:37:04 +01:00
health_test.go Merge pull request #43997 from thaJeztah/healthcheck_capture_logs 2022-09-02 10:48:22 +02:00
inspect_test.go daemon: add annotations to container HostConfig 2023-02-23 18:59:00 -05:00
ipcmode_linux_test.go rootless: support --ipc=host 2023-01-21 01:00:27 +09:00
kill_test.go integration/windows: Unskip some kill tests 2023-08-09 14:29:06 +02:00
links_linux_test.go integration: inline filters in tests 2023-04-25 15:15:50 +02:00
logs_test.go integration: Extract StopContainerWindowsPollTimeout const 2023-03-06 16:21:55 +01:00
main_test.go testutil: make testing packages public 2019-09-11 07:47:23 -05:00
mounts_linux_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
nat_test.go integration: TestNetworkLoopbackNat is broken on GitHub Runner 2022-09-07 22:52:34 +02:00
overlayfs_linux_test.go integration: Add test for not breaking overlayfs 2023-08-18 15:32:04 +02:00
pause_test.go use consistent alias for containerd's errdefs package 2023-04-08 19:30:33 +02:00
pidmode_linux_test.go rootless: support --pid=host 2021-02-01 14:55:18 +09:00
ps_test.go integration: inline filters in tests 2023-04-25 15:15:50 +02:00
remove_test.go api: add types/volume.ListOptions for a more consistent API 2022-08-03 23:30:28 +02:00
rename_test.go client: ContainerStop(), ContainerRestart(): support stop-signal 2022-04-20 21:29:34 +02:00
resize_test.go Prepare tests for Windows containerd support 2021-04-22 10:50:00 +03:00
restart_test.go daemon: daemon.containerRestart: don't cancel restart on context cancel 2023-10-24 16:29:20 +02:00
run_cgroupns_linux_test.go integration: port TestRunModePIDHost from CLI test to API test 2021-02-01 14:54:07 +09:00
run_linux_test.go daemon: fix under what conditions container's mac-address is applied 2023-09-14 11:48:16 +02:00
stats_test.go Merge pull request #40478 from cpuguy83/dont-prime-the-stats 2020-04-16 20:57:06 +02:00
stop_linux_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
stop_test.go integration: Extract StopContainerWindowsPollTimeout const 2023-03-06 16:21:55 +01:00
stop_windows_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00
update_linux_test.go test-integration: support cgroup2 2020-06-22 14:17:45 +09:00
update_test.go bump gotest.tools v3.0.1 for compatibility with Go 1.14 2020-02-11 00:06:42 +01:00
wait_test.go integration: Don't env cleanup before parallel subtests 2023-07-13 15:06:36 +02:00