restore terminal when terminating after 3 signals#6058
Merged
thaJeztah merged 1 commit intodocker:masterfrom May 12, 2025
Merged
restore terminal when terminating after 3 signals#6058thaJeztah merged 1 commit intodocker:masterfrom
thaJeztah merged 1 commit intodocker:masterfrom
Conversation
When attaching to a container, hijack puts the terminal in raw mode, and local echo is disabled. In normal cases, the terminal is restored once the container detaches; https://github.com/docker/cli/blob/6f856263c2f03a8dc19cef3d6cb48d56a3fab5cc/cli/command/container/hijack.go#L40-L44 However, when the CLI is forced to exit (after 3 signals), we `os.Exit(1)`, which causes defers to not be executed, and because of this, the terminal not being restored. For example; start a container that's attached; docker run -it --rm --sig-proxy=false alpine sleep 20 In another terminal send a SIGINT 3 times to force terminate; kill -sINT $(pgrep -af docker\ run) kill -sINT $(pgrep -af docker\ run) kill -sINT $(pgrep -af docker\ run) The first terminal shows that the docker cli was terminated; got 3 SIGTERM/SIGINTs, forcefully exiting However, the terminal was not restored, so local echo is disabled, and typing any command in the terminal does not show output (a manual `stty echo` is needed to restore). With this patch, the terminal is restored before we forcefully exit the docker CLI. Restoring is a no-op if there's no previous state, so we can unconditionally execute this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
There was a problem hiding this comment.
Pull Request Overview
This PR ensures that the terminal is restored to its previous state when the Docker CLI is forcefully terminated after receiving three termination signals.
- Added a call to restore the terminal state in both the plugin termination logic and the force-exit function.
- Changed the parameter type from io.Writer to command.Streams in forceExitAfter3TerminationSignals and removed an unused import.
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files🚀 New features to boost your workflow:
|
Benehiko
approved these changes
May 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When attaching to a container, hijack puts the terminal in raw mode, and local echo is disabled. In normal cases, the terminal is restored once the container detaches;
cli/cli/command/container/hijack.go
Lines 40 to 44 in 6f85626
However, when the CLI is forced to exit (after 3 signals), we
os.Exit(1), which causes defers to not be executed, and because of this, the terminal not being restored.For example; start a container that's attached;
In another terminal send a SIGINT 3 times to force terminate;
The first terminal shows that the docker cli was terminated;
However, the terminal was not restored, so local echo is disabled, and typing any command in the terminal does not show output (a manual
stty echois needed to restore).With this patch, the terminal is restored before we forcefully exit the docker CLI. Restoring is a no-op if there's no previous state, so we can unconditionally execute this.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)