-
-
Notifications
You must be signed in to change notification settings - Fork 941
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
SSH exception after client connect using .NET 3.5 version #113
Comments
Just to confirm I'm getting exactly the same issue with the 3.5 library. |
Same problem. Any solution? |
Has there been any work done on this? Do we know why is the session hanging on that WaitOnHandle()? Where is that event set in 4.0? |
I cannot seem to reproduce this problem, but I'm pretty sure the exception originally comes from When an exception occurs in Can you reproduce the problem using nothing but a simple connect? using (var client = new SshClient(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "pwd"))))
{
client.ErrorOccurred += (sender, e) => Console.WriteLine(e.Exception);
client.Connect();
} Can someone provide the absolute minimum amount of code to reproduce the problem? Thanks! |
Yes. I was just able to reproduce this by just using the above code.
Here is the bare minimum needed. Exception on Connect when compiled in 3.5.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Security;
using Renci.SshNet;
using Renci.SshNet.Common;
using System.IO;
namespace scp
{
class Program
{
private static void Main()
{
using (var client = new SshClient(new ConnectionInfo("host",
"root", new PasswordAuthenticationMethod("user", "password"))))
{
client.ErrorOccurred += (sender, e) =>
Console.WriteLine(e.Exception);
client.Connect();
}
}
}
}
…On Wed, Jan 18, 2017 at 1:34 PM, Gert Driesen ***@***.***> wrote:
I'm pretty sure the exception originally comes from
Session.MessageListener().
When an exception occurs in this method, it is "recorded" and rethrown on
the next call to Session.WaitHandle(...). By rethrowing the exception
later, the original stacktrace is lost.
Try subscribing to the ErrorOccurred event and log the exception.
Can you reproduce the problem using nothing but a simple connect?
For example:
using (var client = new SshClient(new ConnectionInfo("host", "user", new PasswordAuthenticationMethod("user", "pwd"))))
{
client.ErrorOccurred += (sender, e) => Console.WriteLine(e.Exception);
client.Connect();
}
I cannot seem to reproduce this problem.
For some reason, the readSockets must get cleared, even though the socket
is still considered connected. When we subsequently go through the loop
again, the Socket.Select(...) call will fail because are lists are either
empty or null.
Can someone provide the absolute minimum amount of code to reproduce the
problem?
Also, can you reproduce the issue with both version *2016.0.0* and
*2016.1.0-beta1*?
Thanks!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#113 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADKkVqP8P_S4FRcYf7ds1jPMXTANPAW7ks5rTnc7gaJpZM4Kv_Tx>
.
|
The problem might not be with the SSH library, but with the library and the calling program.
I have the following program, and when I compile it with .4.0 (against a 3.5 build of Renci.SshNet), it works. When I build it on 3.5 (against the same Renci.SshNet build), it errors out.
Here is the program:
using Renci.SshNet;
using System;
using System.Globalization;
using System.Text;
namespace Tssh
{
static class Program
{
static ShellStream _ss;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string [] args)
{
SshClient _ssh;
string _address = "10.75.50.102";
int _port = 22;
try
{
string UserName = "User", Password = "Password";
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(UserName, Password);
Renci.SshNet.ConnectionInfo conInfo = new Renci.SshNet.ConnectionInfo(_address, _port, UserName, pauth)
{
Timeout = TimeSpan.FromMilliseconds(30000),
Encoding = Encoding.ASCII,
};
_ssh = new SshClient(conInfo);
Console.WriteLine("Connecting to {0}:{1} as {2}...", _address, _port, UserName);
_ssh.Connect();
_ss = _ssh.CreateShellStream("TM8", 120, 35, 800, 600, 0x10000);
string resp = Read();
Console.Write(resp);
_ss.WriteLine("VER");
resp = Read();
Console.Write(resp);
string line;
do
{
line = Console.ReadLine();
_ss.WriteLine(line);
resp = Read();
int idx = resp.IndexOf(line);
resp = resp.Substring(line.Length + 2);
Console.Write(resp);
} while (!line.EndsWith("exit", true, CultureInfo.InvariantCulture));
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
if (_ssh != null && _ssh.IsConnected)
{
_ssh.Disconnect();
_ssh.Dispose();
_ssh = null;
}
Console.WriteLine("Connection with {0} is closed.", _address);
Console.WriteLine("Type ENTER to exit...");
Console.ReadLine();
}
}
static string Read()
{
string resp = "";
do
{
resp += _ss.Read();
} while (!resp.EndsWith("> ") && !resp.Contains("Good bye!\r\n"));
return resp;
}
And here is the error when I compile it against 3.5 (it dies on the SshClient.Connect() call):
System.ArgumentNullException: Value cannot be null.
Parameter name: All lists are either null or empty.
|
Was able to reproduce the issue, and found the cause Apparently there's no fix available (nor expected), so I'll have to introduce a workaround. |
I have some insight into this. In fact I've been fighting it for the day. The issue is that in Session.cs in the method MessageListener. Inside the while loop there's a line of code Socket.Select(readsockets, null, null, -1); For some oddball reason after a few iterations of the readsockets array runs empty (I'm guessing being edited internally by .Select). In any case on a subsequent run through it will toss an Argument Null Exception. I created this problem by compiling in Visual Studio 2012 for .NET 3.5 and then executing the .dll from a CLR/CLI C++ application in Visual Studio 2008. C++ CLR/CLI apps in Visual Studio 2012 .NET 4 are not affected. This is the fix I'm playing with. Replace the line in Session.cs in method MessageListener Socket.Select and .Poll do roughly the same thing but .Poll is only focusing on single socket whereas .Select can focus on multiple. |
…ption after client connect sshnet#113 Addressing the outstanding issue .NET 3.5 compiled version of SSH exception after client connect sshnet#113 opened by haimiko. Replaced Socket.Select(readSockets, null, null, -1) with _socket.Poll(-1, SelectMode.SelectRead); When executing the .Net 3.5 code in a Visual Studio 2008 C++ CLR session Socket.Select would return an ArgumentNullException. Upon investigation while reading in data the readSockets list would go from a count of 1 to a count of 0 upon execution of Socket.Select. I'm thinking that Socket.Select was editing the contents of the array. Looking at the comments it appears that the use of Socket.Select over .Poll is preferred so please feel free to disregard these changes.
Thank you Best09! That fixes it for me too. |
… -1 is specified as timeout. More information is available here: https://support.microsoft.com/kb/2615314 Fixes issue #113.
Fixed by commit 710aa37 in the develop branch. |
Note that I also updated the appveyor (CI) config to run our unit tests against both .NET 3.5 and .NET 4.0. |
Under Session.cs->MessageListener I put |
Please, could you upload the binaries for .NET Framework 3.5? I have the same problem. I am using Visual Studio 2008 and .NET Framework 3.5. I highly appreciate you. Last binaries is from 14 Dec 2016 and the fix was applied before this date. So where is the binary for .NET Framework 3.5 with this fix applied? could you provide me? Also, could you provide the solution for Visual Studio 2008? I have downloaded the zip package from developer branch and then I have open the source project "Renci.SshNet.NET35" but when I build it I get errors. it's urgent. thx. |
I'm able to successfully work with the .NET 4.0 version of SSH.NET but am experiencing issues with a when both the ssh.net and main project are .NET 3.5 version right after the client connect. I get a "value cannot be null" exception. This does not happen when the main project is .net 4.0 and SSH.NET is .NET 3.5.
I've tried both password and keyfile authentication and both exhibit the same issue. See attached code for the way I'm using Renci.SSH. sshclient.cs
System.ArgumentNullException was caught
Message=Value cannot be null.
Parameter name: All lists are either null or empty.
Source=Renci.SshNet
ParamName=All lists are either null or empty.
StackTrace:
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) in Session.cs:line 812
at Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle) in Session.cs:line 783
at Renci.SshNet.Session.Connect() in Session.cs:line 643
at Renci.SshNet.BaseClient.Connect() BaseClient.cs:line 214
at SSH.clientSSH(ConnectionInfo connectionInfo, String Computer, String command) in SSH.cs:line 225
InnerException: null
More specifically, line 643 in Session.cs (WaitOnHandle(_keyExcahangeCompletedWaitHandle) is what's failing.
The text was updated successfully, but these errors were encountered: