New Post: how to open more than 10 channels using a single connection object for multithreading
New Post: how to open more than 10 channels using a single connection object for multithreading
Btw. IMHO your approach to increase the Limit is a wrong way to "fix" this.
Your code must handle those exceptions and have a kind of command-queue.
The limit exists for a reason, e.g. to prevent DOS attacks.
New Post: how to open more than 10 channels using a single connection object for multithreading
Yes service restarted
kayhan yuksel
From: da_rinkes
You have restarted the ssh-server?Read the full discussion online.
To add a post to this discussion, reply to this email ([email removed])
To start a new discussion for this project, email [email removed]
You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.
Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com
Created Unassigned: SCPClient hangs (downloading) when connections problem occurred [1894]
Simple way of reproduction:
1. Remove scp (/var/bin/scp) from remote mashine.
2. Try to download some file from this mashine.
3. Downloading hungs...
I think, there is some problem with PipeStream interaction (PipeStream has no reaction on disconnect or other connection problems).
------- My Code
_scp = new Renci.SshNet.ScpClient(_host, _login, _password);
_scp.Connect();
_scp.Download(filename, file);
------- First hangs thread:
> Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read(byte[] buffer, int offset, int count) Line 181 + 0xb bytes C#
mscorlib.dll!System.IO.Stream.ReadByte() + 0x28 bytes
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadByte(System.IO.Stream stream) Line 367 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadString(System.IO.Stream stream) Line 384 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.InternalDownload(Renci.SshNet.Channels.ChannelSession channel, System.IO.Stream input, System.IO.FileSystemInfo fileSystemInfo) Line 217 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.Download(string filename, System.IO.FileInfo fileInfo) Line 132 + 0x14 bytes C#
> Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read(byte[] buffer, int offset, int count) Line 181 + 0xb bytes C#
...
while (!this.ReadAvailable(count))
> Monitor.Wait(this._buffer); // (will hungs infinite due to disconnection state - no one will write in PipeStream)
------- Second hangs thread:
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) + 0xc6 bytes
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x20 bytes
>Renci.SshNet.dll!Renci.SshNet.Session.SocketRead(int length, ref byte[] buffer) Line 115 + 0x34 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Read(int length) Line 1500 + 0xf bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 805 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1582 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 529 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3c(object o) Line 25 + 0xf bytes C#
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x2d bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5a bytes
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x147 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x2d bytes
[Native to Managed Transition]
partial void SocketRead(int length, ref byte[] buffer)
{
var offset = 0;
int receivedTotal = 0; // how many bytes is already received
do
{
try
{
var receivedBytes = this._socket.Receive(buffer, offset + receivedTotal, length - receivedTotal, SocketFlags.None);
if (receivedBytes > 0)
------- output ----------------
SshNet.Logging Verbose: 1 : Initiating connect to '.............'.
SshNet.Logging Verbose: 1 : Server version '2.0' on 'OpenSSH_5.9p1 Debian-5ubuntu1.1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeRequest': 'SSH_MSG_KEX_DH_GEX_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeGroup': 'SSH_MSG_KEX_DH_GEX_GROUP'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeInit': 'SSH_MSG_KEX_DH_GEX_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeReply': 'SSH_MSG_KEX_DH_GEX_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
The thread '<No Name>' (0x724) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelWindowAdjustMessage': 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelExtendedDataMessage': 'SSH_MSG_CHANNEL_EXTENDED_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0x2254) has exited with code 0 (0x0).
The thread '<No Name>' (0x1474) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0xeb8) has exited with code 0 (0x0).
The thread '<No Name>' (0x27d8) has exited with code 0 (0x0).
The thread '<No Name>' (0x13f8) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
Created Unassigned: SCPClient hangs (downloading) when connections problem occurred [1895]
Simple way of reproduction:
1. Remove scp (/var/bin/scp) from remote mashine.
2. Try to download some file from this mashine.
3. Downloading hungs...
I think, there is some problem with PipeStream interaction (PipeStream has no reaction on disconnect or other connection problems).
------- My Code
_scp = new Renci.SshNet.ScpClient(_host, _login, _password);
_scp.Connect();
_scp.Download(filename, file);
------- First hangs thread:
> Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read(byte[] buffer, int offset, int count) Line 181 + 0xb bytes C#
mscorlib.dll!System.IO.Stream.ReadByte() + 0x28 bytes
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadByte(System.IO.Stream stream) Line 367 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.ReadString(System.IO.Stream stream) Line 384 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.InternalDownload(Renci.SshNet.Channels.ChannelSession channel, System.IO.Stream input, System.IO.FileSystemInfo fileSystemInfo) Line 217 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.ScpClient.Download(string filename, System.IO.FileInfo fileInfo) Line 132 + 0x14 bytes C#
> Renci.SshNet.dll!Renci.SshNet.Common.PipeStream.Read
...
while (!this.ReadAvailable(count))
Monitor.Wait(this._buffer); // (will hungs infinite due to disconnection state - no one will write in PipeStream)
------- Second hangs thread:
> System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, out System.Net.Sockets.SocketError errorCode) + 0xc6 bytes
System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x20 bytes
Renci.SshNet.dll!Renci.SshNet.Session.SocketRead(int length, ref byte[] buffer) Line 115 + 0x34 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Read(int length) Line 1500 + 0xf bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ReceiveMessage() Line 805 + 0xb bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.MessageListener() Line 1582 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.Connect.AnonymousMethod__4() Line 529 + 0x8 bytes C#
Renci.SshNet.dll!Renci.SshNet.Session.ExecuteThread.AnonymousMethod__3c(object o) Line 25 + 0xf bytes C#
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(object state) + 0x2d bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xb0 bytes
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() + 0x5a bytes
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() + 0x147 bytes
mscorlib.dll!System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() + 0x2d bytes
[Native to Managed Transition]
partial void SocketRead(int length, ref byte[] buffer)
{
var offset = 0;
int receivedTotal = 0; // how many bytes is already received
do
{
try
{
var receivedBytes = this._socket.Receive(buffer, offset + receivedTotal, length - receivedTotal, SocketFlags.None); // hungs here
if (receivedBytes > 0)
------- output ----------------
SshNet.Logging Verbose: 1 : Initiating connect to '.............'.
SshNet.Logging Verbose: 1 : Server version '2.0' on 'OpenSSH_5.9p1 Debian-5ubuntu1.1'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Dynamic\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Dynamic.dll'
'TestDownload.vshost.exe' (Managed (v4.0.30319)): Loaded 'Anonymously Hosted DynamicMethods Assembly'
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeInitMessage': 'SSH_MSG_KEXINIT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeRequest': 'SSH_MSG_KEX_DH_GEX_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeGroup': 'SSH_MSG_KEX_DH_GEX_GROUP'.
SshNet.Logging Verbose: 1 : SendMessage to server 'KeyExchangeDhGroupExchangeInit': 'SSH_MSG_KEX_DH_GEX_INIT'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'KeyExchangeDhGroupExchangeReply': 'SSH_MSG_KEX_DH_GEX_REPLY'.
SshNet.Logging Verbose: 1 : SendMessage to server 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'NewKeysMessage': 'SSH_MSG_NEWKEYS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ServiceRequestMessage': 'SSH_MSG_SERVICE_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ServiceAcceptMessage': 'SSH_MSG_SERVICE_ACCEPT'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessageNone': 'SSH_MSG_USERAUTH_REQUEST'.
The thread '<No Name>' (0x724) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'FailureMessage': 'SSH_MSG_USERAUTH_FAILURE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'RequestMessagePassword': 'SSH_MSG_USERAUTH_REQUEST'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'SuccessMessage': 'SSH_MSG_USERAUTH_SUCCESS'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelOpenMessage': 'SSH_MSG_CHANNEL_OPEN : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelOpenConfirmationMessage': 'SSH_MSG_CHANNEL_OPEN_CONFIRMATION : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelWindowAdjustMessage': 'SSH_MSG_CHANNEL_WINDOW_ADJUST : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelSuccessMessage': 'SSH_MSG_CHANNEL_SUCCESS : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelRequestMessage': 'SSH_MSG_CHANNEL_REQUEST : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelDataMessage': 'SSH_MSG_CHANNEL_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelExtendedDataMessage': 'SSH_MSG_CHANNEL_EXTENDED_DATA : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelEofMessage': 'SSH_MSG_CHANNEL_EOF : #0'.
SshNet.Logging Verbose: 1 : ReceiveMessage from server: 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'ChannelCloseMessage': 'SSH_MSG_CHANNEL_CLOSE : #0'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0x2254) has exited with code 0 (0x0).
The thread '<No Name>' (0x1474) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
The thread '<No Name>' (0xeb8) has exited with code 0 (0x0).
The thread '<No Name>' (0x27d8) has exited with code 0 (0x0).
The thread '<No Name>' (0x13f8) has exited with code 0 (0x0).
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
SshNet.Logging Verbose: 1 : SendMessage to server 'IgnoreMessage': 'SSH_MSG_IGNORE'.
New Post: how to open more than 10 channels using a single connection object for multithreading
Used a list like 'List<SSHClient> clients' and added as many as NumOfSSHObjects.
NumOfSSHObjects = NumOfCommands / 10;
if ( (NumOfCommands % 10 ) > 0)
{
NumOfSSHObjects = NumOfSSHObjects +1 ;
}for (int i = 1; i <= NumOfSSHObjects ; i++)
{
clients.Add(new SshClient(connectionInfo));
}
New Post: how to open more than 10 channels using a single connection object for multithreading
Now you are just guessing its 10.
Don't know for what/who you are writing this code, but if your code hits a
server with a session limit of 5, then you do what?
This is a really bad workaround, cause you do a lot of heavy cpu asymetric crypto for nothing.
New Post: how to open more than 10 channels using a single connection object for multithreading
Currently this is a project to be used for inhouse purposes but the correct way to go is as you have pointed out. Do you have any other alternative ways in mind ?
New Post: Getting /bin/env xxxx no such file or directory
I am starting to use SSH. net
When I use putty I can login and then run a command with success. After log in I type the following command:
"/usr/local/bin/runTest-ccc 10.218.48.120 neo neo c-test 1"
When I execute the command using SSH.net library I get an error:
/bin/env <name of a library> no such file or directory.
Could you give me an idea why it is giving me the error? Below, my 2 lines of code:
var cmd = client.RunCommand("/usr/local/bin/runTest-ccc 10.218.48.120 neo neo c-test 1");
cmd.Execute();
Thanks,
New Post: Getting /bin/env xxxx no such file or directory
New Post: Slow Performance .... help!!
Here is my code, any help would appreciated.
var connectionInfo = new PasswordConnectionInfo("host", "username", "password");
var encoding = new ASCIIEncoding();
using (var client = new SshClient(connectionInfo))
{
client.Connect();
client.DownloadFile("/largefile.txt", new FileStream(@"C:\largefile.txt", FileMode.Create, FileAccess.Write), null);
client.Disconnect();
}
New Post: Slow Performance .... help!!
Source code checked in, #34518
New Post: Slow Performance .... help!!
private static void DownloadFile(string ip, string user, string password, string file)
{
using (var client = new SftpClient(ip, user, password))
{
client.Connect();
var filestream = new FileStream("bla", FileMode.OpenOrCreate);
var start = DateTime.Now;
client.DownloadFile(file, filestream);
var end = DateTime.Now;
var timespan = TimeSpan.FromSeconds((end - start).TotalSeconds);
var size = (new FileInfo("bla").Length / 1024) / 1024;
Console.WriteLine("{0} {1}", timespan.TotalSeconds , size);
var speed = size/timespan.TotalSeconds;
Console.WriteLine("Speed: {0} MB/s", speed);
}
}
(I know this code is not very good for performance measurements ;))I get around 4-5 MB/s while downloading a 100MB file or a 1GB file
My bottleneck is my not so fast linux nas ^^
Btw, why is nobody able to paste his real code? That is quite frustrating..
Commented Unassigned: SSHNET Issue [1789]
so is there any way to open it in vs 2010 ? or is there any link from where i can download SSHNET which is created in vs 2010 ?
Comments: ** Comment from web user: drieseng **
Do you actually need the Visual Studio project file ?
Why not just reference the assembly (from the downloads section), or the NuGet package ?
Closed Issue: OverflowException on empty server response [1562]
I'm trying to connect to OS X Mountain Lion from a Windows Phone 7.5 application using a SFTP client implemented using your library (version 2013.4.7), and upon sftpclient.connect, after a few seconds of it apparently waiting for something, it crashes with OverflowException. Debugging in the source code the OverflowException is thrown in line 88 of Session.SilverlightShared.cs:
```
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
At this point buffer.Count = 0, so buffer.Count -1 is actually -1.
Looking up it did break at:
```
// If zero bytes received then exit
if (args.BytesTransferred == 0)
break;
```
However in the subsequent tests that case doesn't seem handled:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
So I added a simple line as follows and now I do get the "Server string is null or empty" exception as expected:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count == 0) response = string.Empty; // <-- this line right here
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
Comments: This issue was fixed by Oleg on July 10th 2013 (changeset 28764), and will be part of the next release.
Reopened Issue: Error: Message type 52 is not valid [652]
All the clients use the same ConnectionInfo object to connect.
The following exception occurs either on Connect, or RunCommand, but mostly on Connect.
Renci.SshClient.Common.SshException: Message type 52 is not valid.
at Renci.SshClient.Session.WaitHandle(WaitHandle waitHandle)
at Renci.SshClient.PasswordConnectionInfo.OnAuthenticate()
at Renci.SshClient.ConnectionInfo.Authenticate(Session session)
at Renci.SshClient.Session.Connect()
at Renci.SshClient.BaseClient.Connect()
at upresources.LinuxSSH.Process(Object sender, DoWorkEventArgs e)
I have seen this behaviour with the max number of threads set to 3, but that was in debug-mode in VS 2010.
Please tell me if there's additional information I can provide.
Commented Issue: Error: Message type 52 is not valid [652]
All the clients use the same ConnectionInfo object to connect.
The following exception occurs either on Connect, or RunCommand, but mostly on Connect.
Renci.SshClient.Common.SshException: Message type 52 is not valid.
at Renci.SshClient.Session.WaitHandle(WaitHandle waitHandle)
at Renci.SshClient.PasswordConnectionInfo.OnAuthenticate()
at Renci.SshClient.ConnectionInfo.Authenticate(Session session)
at Renci.SshClient.Session.Connect()
at Renci.SshClient.BaseClient.Connect()
at upresources.LinuxSSH.Process(Object sender, DoWorkEventArgs e)
I have seen this behaviour with the max number of threads set to 3, but that was in debug-mode in VS 2010.
Please tell me if there's additional information I can provide.
Comments: ** Comment from web user: drieseng **
I can reproduce this consistently when using the same ConnectionInfo for multiple connections (on multiple threads).
This is because the authentication methods are not thread-safe. The EventWaitHandle and authentication result are on the AuthenticationMethod, and - when its shared by multiple threads - it can lead to the exception mentioned in this issue.
When the EventWaitHandle of an Authenticate invocation for a given session is actually getting set by the authentication attempt of another session, then SSH_MSG_USERAUTH_SUCCESS (and others) is unregistered while the session itself still has to receive this message. Once it receives the message, the exception above is thrown.
Reopened Issue: OverflowException on empty server response [1562]
I'm trying to connect to OS X Mountain Lion from a Windows Phone 7.5 application using a SFTP client implemented using your library (version 2013.4.7), and upon sftpclient.connect, after a few seconds of it apparently waiting for something, it crashes with OverflowException. Debugging in the source code the OverflowException is thrown in line 88 of Session.SilverlightShared.cs:
```
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
At this point buffer.Count = 0, so buffer.Count -1 is actually -1.
Looking up it did break at:
```
// If zero bytes received then exit
if (args.BytesTransferred == 0)
break;
```
However in the subsequent tests that case doesn't seem handled:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
So I added a simple line as follows and now I do get the "Server string is null or empty" exception as expected:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count == 0) response = string.Empty; // <-- this line right here
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
Edited Issue: OverflowException on empty server response [1562]
I'm trying to connect to OS X Mountain Lion from a Windows Phone 7.5 application using a SFTP client implemented using your library (version 2013.4.7), and upon sftpclient.connect, after a few seconds of it apparently waiting for something, it crashes with OverflowException. Debugging in the source code the OverflowException is thrown in line 88 of Session.SilverlightShared.cs:
```
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
At this point buffer.Count = 0, so buffer.Count -1 is actually -1.
Looking up it did break at:
```
// If zero bytes received then exit
if (args.BytesTransferred == 0)
break;
```
However in the subsequent tests that case doesn't seem handled:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
So I added a simple line as follows and now I do get the "Server string is null or empty" exception as expected:
```
if (buffer.Count > 0 && buffer[buffer.Count - 1] == 0x00)
{
response = string.Empty;
}
else if (buffer.Count == 0) response = string.Empty; // <-- this line right here
else if (buffer.Count > 1 && buffer[buffer.Count - 2] == 0x0D)
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 2);
else
response = encoding.GetString(buffer.ToArray(), 0, buffer.Count - 1);
```
Comments: ** Comment from web user: drieseng **
Let's keep the issue open (with status Resolved) until we release a version that contains this fix.