Skip to content

fix: Improve shutdown procedure of ssh, portforward, wgtunnel cmds #3354

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

Merged
merged 3 commits into from
Aug 2, 2022

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Aug 2, 2022

We could turn it into a practice to wrap cmd.Context() so that we have
more fine-grained control of cancellation. Sometimes in tests we may be
running commands with a context that is never canceled.

Related to #3221

We could turn it into a practice to wrap `cmd.Context()` so that we have
more fine-grained control of cancellation. Sometimes in tests we may be
running commands with a context that is never canceled.

Related to #3221
@mafredri mafredri self-assigned this Aug 2, 2022
@mafredri mafredri requested a review from a team August 2, 2022 13:40
@@ -224,13 +236,17 @@ func ssh() *cobra.Command {

sshSession.Stdin = cmd.InOrStdin()
sshSession.Stdout = cmd.OutOrStdout()
sshSession.Stderr = cmd.OutOrStdout()
sshSession.Stderr = cmd.ErrOrStderr()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a drive-by change I did. It seemed wrong but perhaps I didn't understand the purpose?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me!

Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in-between on whether this is desired or not, but I suppose it is. It seems weird to not use the command context directly, but then the caller (like our tests) is responsible for canceling it, which is even weirder I suppose.

@mafredri
Copy link
Member Author

mafredri commented Aug 2, 2022

I'm in-between on whether this is desired or not, but I suppose it is. It seems weird to not use the command context directly, but then the caller (like our tests) is responsible for canceling it, which is even weirder I suppose.

We're still inheriting it, so in that sense we're still using it. I think this change can make more sense if we consider other scenarios, like adding tracing to the commands. We'd want to ensure that the context we're passing along contains the tracing information which means we shouldn't be accessing the command context directly.

@mafredri mafredri merged commit 83c63d4 into main Aug 2, 2022
@mafredri mafredri deleted the mafredri/command-closure branch August 2, 2022 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants