Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[27.1 backport] fix: container stream should not be terminated by ctx #5250

Merged
merged 3 commits into from
Jul 12, 2024

Conversation

Benehiko
Copy link
Member

@Benehiko Benehiko commented Jul 12, 2024

- What I did
Prevent the hijacked stream from exiting on main ctx cancellation. When the user sends a termination signal to the CLI while attached to a container, the signal should be forwarded to the container and handled by the process inside the container. The CLI should wait for the container to gracefully exit.

If the user wishes to exit without waiting, sending more termination requests will still forcefully exit the CLI.

- How I did it

- How to verify it

handle_sigterm.sh

#!/bin/sh

# Function to handle SIGTERM
handle_sigterm() {
    echo "Received SIGTERM, exiting..."
    exit 0
}

trap 'handle_sigterm' TERM

while true; do
    echo "Waiting for sigterm"
    sleep 10
done
⋊> ~/G/cli on hotfix-sigterm-container ◦ build/docker run -i \                                                    
                                                      -v $HOME/Downloads/:/home:ro \
                                                      alpine:latest \
                                                      /home/handle_sigterm.sh
Waiting for sigterm
Waiting for sigterm
Received SIGTERM, exiting...
⋊> ~ ps -ef | grep "handle_sigterm.sh" | grep "docker run"
benehiko  279458  277233  1 17:48 pts/5    00:00:00 build/docker run -i -v /home/benehiko/Downloads/:/home:ro alpine:latest /home/handle_sigterm.sh
⋊> ~ kill -15 279458 

- Description for the changelog

sending a termination request to the CLI while attached to a container, will wait for the container to exit before closing the stream.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.42%. Comparing base (52848fb) to head (333103d).

Additional details and impacted files
@@           Coverage Diff           @@
##             27.0    #5250   +/-   ##
=======================================
  Coverage   61.42%   61.42%           
=======================================
  Files         298      298           
  Lines       20815    20816    +1     
=======================================
+ Hits        12785    12786    +1     
+ Misses       7117     7114    -3     
- Partials      913      916    +3     

@Benehiko Benehiko requested a review from vvoland July 12, 2024 13:50
@vvoland vvoland added this to the 27.0.4 milestone Jul 12, 2024
@vvoland vvoland merged commit 69a2c9f into docker:27.0 Jul 12, 2024
104 checks passed
@Benehiko Benehiko deleted the 27.0-container-ctx branch July 12, 2024 14:23
@thaJeztah thaJeztah changed the title [27.0 backport] fix: container stream should not be terminated by ctx [27.1 backport] fix: container stream should not be terminated by ctx Jul 19, 2024
renovate bot added a commit to earthly/dind that referenced this pull request Jul 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker/docker](https://togithub.com/docker/docker) | minor | `27.0.3`
-> `27.1.0` |

---

### Release Notes

<details>
<summary>docker/docker (docker/docker)</summary>

### [`v27.1.0`](https://togithub.com/moby/moby/releases/tag/v27.1.0)

[Compare
Source](https://togithub.com/docker/docker/compare/v27.0.3...v27.1.0)

#### 27.1.0

For a full list of pull requests and changes in this release, refer to
the relevant GitHub milestones:

- [docker/cli, 27.1.0
milestone](https://togithub.com/docker/cli/issues?q=is%3Aclosed+milestone%3A27.1.0)
- [moby/moby, 27.1.0
milestone](https://togithub.com/moby/moby/issues?q=is%3Aclosed+milestone%3A27.1.0)
- Deprecated and removed features, see [Deprecated
Features](https://togithub.com/docker/cli/blob/v27.1.0/docs/deprecated.md).
- Changes to the Engine API, see [API version
history](https://togithub.com/moby/moby/blob/v27.1.0/docs/api/version-history.md).

##### Bug fixes and enhancements

- rootless: add `Requires=dbus.socket` to prevent errors when starting
the daemon on a cgroup v2 host with systemd
[moby/moby#48141](https://togithub.com/moby/moby/pull/48141)
- containerd integration: `image tag` event is now properly emitted when
building images with Buildkit
[moby/moby#48182](https://togithub.com/moby/moby/pull/48182)
- cli: add OOMScoreAdj to docker service create and docker stack
[docker/cli#5274](https://togithub.com/docker/cli/pull/5274)
- cli: add support for `DOCKER_CUSTOM_HEADERS` env-var (experimental)
[docker/cli#5271](https://togithub.com/docker/cli/pull/5271)
- cli: containerd-integration: Fix `docker push` defaulting the
`--platform` flag to a value of `DOCKER_DEFAULT_PLATFORM` environment
variable on unsupported API versions
[docker/cli#5248](https://togithub.com/docker/cli/pull/5248)
- cli: fix: ctx cancellation on login prompt
[docker/cli#5260](https://togithub.com/docker/cli/pull/5260)
- cli: fix: wait for the container to exit before closing the stream
when sending a termination request to the CLI while attached to a
container [docker/cli#5250](https://togithub.com/docker/cli/pull/5250)

##### Deprecated

- the pkg/rootless/specconv package is deprecated, an will be removed in
the next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- the pkg/containerfs package is deprecated, an will be removed in the
next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- the pkg/directory package is deprecated, an will be removed in the
next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- api/types/system: remove deprecated Info.ExecutionDriver
[moby/moby#48184](https://togithub.com/moby/moby/pull/48184)

##### Packaging updates

- Update Buildx to
[v0.16.1](https://togithub.com/docker/buildx/releases/tag/v0.16.1).
[moby/docker-ce-packaging#1039](https://togithub.com/docker/docker-ce-packaging/pull/1039)
- Update Compose to
[v2.29.0](https://togithub.com/docker/compose/releases/tag/v2.29.0).
[moby/docker-ce-packaging#1038](https://togithub.com/docker/docker-ce-packaging/pull/1038)
- Update Containerd (static binaries only) to
[v1.7.20](https://togithub.com/containerd/containerd/releases/tag/v1.7.20).
[moby/moby#48191](https://togithub.com/moby/moby/pull/48191)
- Update BuildKit to
[v0.15.0](https://togithub.com/moby/buildkit/releases/tag/v0.15.0).
[moby/moby#48028](48175://togithub.com/moby/moby/pull/48175)
- Update Go runtime to 1.21.12, which contains security fixes for
[CVE-2024-24791](https://togithub.com/advisories/GHSA-hw49-2p59-3mhj)
[moby/moby#48120](48175://togithub.com/moby/moby/pull/48120)

**Full Changelog**:
moby/moby@v27.0.3...v27.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6am on monday" (UTC), Automerge
- At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/earthly/dind).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzguMCIsInVwZGF0ZWRJblZlciI6IjM3LjQzOC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZSJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to earthly/dind that referenced this pull request Jul 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [docker/docker](https://togithub.com/docker/docker) | minor | `27.0.3`
-> `27.1.0` |

---

### Release Notes

<details>
<summary>docker/docker (docker/docker)</summary>

### [`v27.1.0`](https://togithub.com/moby/moby/releases/tag/v27.1.0)

[Compare
Source](https://togithub.com/docker/docker/compare/v27.0.3...v27.1.0)

#### 27.1.0

For a full list of pull requests and changes in this release, refer to
the relevant GitHub milestones:

- [docker/cli, 27.1.0
milestone](https://togithub.com/docker/cli/issues?q=is%3Aclosed+milestone%3A27.1.0)
- [moby/moby, 27.1.0
milestone](https://togithub.com/moby/moby/issues?q=is%3Aclosed+milestone%3A27.1.0)
- Deprecated and removed features, see [Deprecated
Features](https://togithub.com/docker/cli/blob/v27.1.0/docs/deprecated.md).
- Changes to the Engine API, see [API version
history](https://togithub.com/moby/moby/blob/v27.1.0/docs/api/version-history.md).

##### Bug fixes and enhancements

- rootless: add `Requires=dbus.socket` to prevent errors when starting
the daemon on a cgroup v2 host with systemd
[moby/moby#48141](https://togithub.com/moby/moby/pull/48141)
- containerd integration: `image tag` event is now properly emitted when
building images with Buildkit
[moby/moby#48182](https://togithub.com/moby/moby/pull/48182)
- cli: add OOMScoreAdj to docker service create and docker stack
[docker/cli#5274](https://togithub.com/docker/cli/pull/5274)
- cli: add support for `DOCKER_CUSTOM_HEADERS` env-var (experimental)
[docker/cli#5271](https://togithub.com/docker/cli/pull/5271)
- cli: containerd-integration: Fix `docker push` defaulting the
`--platform` flag to a value of `DOCKER_DEFAULT_PLATFORM` environment
variable on unsupported API versions
[docker/cli#5248](https://togithub.com/docker/cli/pull/5248)
- cli: fix: ctx cancellation on login prompt
[docker/cli#5260](https://togithub.com/docker/cli/pull/5260)
- cli: fix: wait for the container to exit before closing the stream
when sending a termination request to the CLI while attached to a
container [docker/cli#5250](https://togithub.com/docker/cli/pull/5250)

##### Deprecated

- the pkg/rootless/specconv package is deprecated, an will be removed in
the next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- the pkg/containerfs package is deprecated, an will be removed in the
next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- the pkg/directory package is deprecated, an will be removed in the
next release
[moby/moby#48185](https://togithub.com/moby/moby/pull/48185)
- api/types/system: remove deprecated Info.ExecutionDriver
[moby/moby#48184](https://togithub.com/moby/moby/pull/48184)

##### Packaging updates

- Update Buildx to
[v0.16.1](https://togithub.com/docker/buildx/releases/tag/v0.16.1).
[moby/docker-ce-packaging#1039](https://togithub.com/docker/docker-ce-packaging/pull/1039)
- Update Compose to
[v2.29.0](https://togithub.com/docker/compose/releases/tag/v2.29.0).
[moby/docker-ce-packaging#1038](https://togithub.com/docker/docker-ce-packaging/pull/1038)
- Update Containerd (static binaries only) to
[v1.7.20](https://togithub.com/containerd/containerd/releases/tag/v1.7.20).
[moby/moby#48191](https://togithub.com/moby/moby/pull/48191)
- Update BuildKit to
[v0.15.0](https://togithub.com/moby/buildkit/releases/tag/v0.15.0).
[moby/moby#48175](https://togithub.com/moby/moby/pull/48175)
- Update Go runtime to 1.21.12, which contains security fixes for
[CVE-2024-24791](https://togithub.com/advisories/GHSA-hw49-2p59-3mhj)
[moby/moby#48120](48175://togithub.com/moby/moby/pull/48120)

**Full Changelog**:
moby/moby@v27.0.3...v27.1.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 6am on monday" (UTC), Automerge
- At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/earthly/dind).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzguMCIsInVwZGF0ZWRJblZlciI6IjM3LjQzOC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZSJdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants