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

SshCommand.Execute deadlock #1506

Open
valeriob opened this issue Sep 25, 2024 · 5 comments
Open

SshCommand.Execute deadlock #1506

valeriob opened this issue Sep 25, 2024 · 5 comments

Comments

@valeriob
Copy link

Hi,
i'm trying latest release 2024.1.0 and i think i found an issue with the api, there is a deadlock in the Renci.SshNet.SshCommand.Execute()

image

is it due the sync over async antipattern ?
image

Probably makes sense to do a fully async api to avoid the issue ?

@Rob-Hague
Copy link
Collaborator

Hmm, could be. Are you running in a GUI / ASP.NET / non-console environment?

Can you reproduce the problem consistently?

If yes, does making this tweak to the library make a difference?

diff --git a/src/Renci.SshNet/SshCommand.cs b/src/Renci.SshNet/SshCommand.cs
index 6bfd5742..96188e4c 100644
--- a/src/Renci.SshNet/SshCommand.cs
+++ b/src/Renci.SshNet/SshCommand.cs
@@ -279,7 +279,7 @@ public Task ExecuteAsync(CancellationToken cancellationToken = default)
             _cts = null;
             _cancellationRequested = false;

-            _tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
+            _tcs = new TaskCompletionSource<object>(TaskCreationOptions.None);
             _userToken = cancellationToken;

             _channel = _session.CreateChannelSession();

@valeriob
Copy link
Author

Hello @Rob-Hague
i'm running on a dotnet 7 console program, it blocks after 1 hour, but id depends on the load i guess.
At the moment i got back to version 2023.0.1 and it's up for one day without issues.

@valeriob
Copy link
Author

Probably the issue is something else, i got a lock also with the older version :
image
i think something gets stuck when the connection is unstable, we are connecting to devices that move around connected via GSM.

Probably more similar to : #462

@Rob-Hague
Copy link
Collaborator

In that case I'm not sure if there is something actionable here. I think my prior comment about TaskCreationOptions was nonsensical because there are no continuations attached to the Task when using the sync Execute

@valeriob
Copy link
Author

At the moment i had to put the ssh command execution on a dedicated thread and add a watchdog to kill if not completed after some timeout.

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

No branches or pull requests

2 participants