Skip to content

A couple of changes/fixes in SshCommand #1423

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 2 commits into from
Jun 9, 2024

Conversation

Rob-Hague
Copy link
Collaborator

  1. in CancelAsync, we were sending exit-signal channel request, when in fact we should be sending signal and the server will respond with exit-signal. This explains why we did not see any response or channel close in Fix CancelAsync Cause Deadlock #1345 (@zeotuan fyi). Add a corresponding string? ExitSignal property which has a value when the server sends one. (closes ExitSignalName #95 - seems like it existed once upon a time).
  2. Previously, we were setting the IAsyncResult.WaitHandle only when the command had completed successfully, or otherwise once EndExecute had been called. But we should be setting it as soon as the command completes whether successfully, with an error or via cancellation. This refactors the logic by removing the extra wait handles and consolidating the completion logic onto the IAsyncResult.WaitHandle. With this refactoring the logic intentionally looks (with some squinting) similar to a Task. Adding ExecuteAsync should only be a small step from here.
  3. Take a breaking change on ExitStatus by changing the return type from int to int?, in order to distinguish between an exit status of 0 and when no exit status has been returned (because for example, an exit signal was returned instead). This is the second commit.

@WojciechNagorski
Copy link
Collaborator

Is it ready for review?

@Rob-Hague
Copy link
Collaborator Author

Yes, thanks

@WojciechNagorski WojciechNagorski merged commit ac395dd into sshnet:develop Jun 9, 2024
1 check passed
@Rob-Hague Rob-Hague deleted the sshcommand branch June 10, 2024 06:32
@Rob-Hague
Copy link
Collaborator Author

Thanks

Rob-Hague added a commit to Rob-Hague/SSH.NET that referenced this pull request Jun 14, 2024
After the previous change (sshnet#1423), this basically entails swapping out the
IAsyncResult for a TaskCompletionSource and hooking up the cancellation/timeout
logic.

As with the prior Begin/End pattern, the initiation of the command (SendExecRequest)
happens synchronously, so there's a bit of room for improvement there, but otherwise
it is the Task-based async that we know and like.

I chose to make it void (Task)- returning instead of string like in the existing
overloads, so that OutputStream is not automatically consumed (and encoded as a
string) when that may not be desired. As in sshnet#650, I was initially considering
changing the other overloads to be void-returning as well, but decided that it was
not worth the break since most people will probably want to change over to
ExecuteAsync anyway.
Rob-Hague added a commit to Rob-Hague/SSH.NET that referenced this pull request Jun 14, 2024
After the previous change (sshnet#1423), this basically entails swapping out the
IAsyncResult for a TaskCompletionSource and hooking up the cancellation/timeout
logic.

As with the prior Begin/End implementation, the initiation of the command
(SendExecRequest) happens synchronously, so there's a bit of room for improvement
there, but otherwise it is the Task-based async that we know and like.

I chose to make it void (Task)- returning instead of string like in the existing
overloads, so that OutputStream is not automatically consumed (and encoded as a
string) when that may not be desired. As in sshnet#650, I was initially considering
changing the other overloads to be void-returning as well, but decided that it was
not worth the break since most people will probably want to change over to
ExecuteAsync anyway.
WojciechNagorski added a commit that referenced this pull request Jun 19, 2024
* Add SshCommand.ExecuteAsync

After the previous change (#1423), this basically entails swapping out the
IAsyncResult for a TaskCompletionSource and hooking up the cancellation/timeout
logic.

As with the prior Begin/End implementation, the initiation of the command
(SendExecRequest) happens synchronously, so there's a bit of room for improvement
there, but otherwise it is the Task-based async that we know and like.

I chose to make it void (Task)- returning instead of string like in the existing
overloads, so that OutputStream is not automatically consumed (and encoded as a
string) when that may not be desired. As in #650, I was initially considering
changing the other overloads to be void-returning as well, but decided that it was
not worth the break since most people will probably want to change over to
ExecuteAsync anyway.

* Update examples

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
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.

ExitSignalName
2 participants