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

ShellStream.Expect TimeSpan timeout, not working. #714

Closed
gavin1970 opened this issue Aug 6, 2020 · 5 comments · Fixed by #1322
Closed

ShellStream.Expect TimeSpan timeout, not working. #714

gavin1970 opened this issue Aug 6, 2020 · 5 comments · Fixed by #1322
Labels
Milestone

Comments

@gavin1970
Copy link

Microsoft Visual Studio Professional 2019 Version 16.6.5
.NET Framework 4.7.2
SSN.NET v2016.1.0

I'm using the latest SSH.NET with ShellStream and when calling the Expect(Regex, TimeSpan) the timeout doesn't seem to work at all. I've also tried using TimeSpan.FromSeconds(30) with the same results. If the expected information comes back, it works fine.

this.shellStream.WriteLine(command);
var expectRegex = new Regex(@"\[(.*?)\][$#]|[$]");
var output = this.shellStream.Expect(expectRegex, new TimeSpan(0, 0, 30));
@gavin1970
Copy link
Author

gavin1970 commented Aug 7, 2020

I ended up, just threading off the writeline / expect then handled the timer with an EventWaitHandle.

@IgorMilavec
Copy link
Collaborator

I have created a discussion #926 for all ShellStream related issues.

@IgorMilavec
Copy link
Collaborator

@gavin1970 at this time the implementation resets the timeout after each byte received. This is definitely something we need to look into.
I'm trying to better understand usage patterns related to Expect API. Can you please explain how you use it and if possible provide a proto code for it?

@biocoder-frodo
Copy link

@IgorMilavec I'm using it in https://github.com/biocoder-frodo/VPNCenter.OpenVPN.PackageConfig and https://github.com/biocoder-frodo/SynoDuplicateFolders to be able to do an interactive sudo command inside an SSH session. I quickly realised that the Regex should be really simple. If you constrain the expression too much, you have no or not enough guarantees that the incoming network stream will deliver the text in the chunk(s) that you need for the Regex to match.
So I chose to respond only to the patterns my host will throw at you when try to run a command using sudo.
For example:
https://github.com/biocoder-frodo/DiskStationManager.SecureShell/blob/11a78f754067ea1ec8e8cbb3420855f6a1044e5b/source/DiskStationManager.SecureShell/SudoSession.cs#L135

@WojciechNagorski
Copy link
Collaborator

This issue has been fixed in the 2024.0.0 version.

@WojciechNagorski WojciechNagorski added this to the 2024.0.0 milestone Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants