-
Notifications
You must be signed in to change notification settings - Fork 2.1k
restore terminal when terminating after 3 signals #6058
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
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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@@ Coverage Diff @@
## master #6058 +/- ##
==========================================
- Coverage 59.07% 59.05% -0.02%
==========================================
Files 358 358
Lines 30013 30023 +10
==========================================
Hits 17731 17731
- Misses 11301 11311 +10
Partials 981 981 🚀 New features to boost your workflow:
|
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)