SSH.NET Peek() hangs (wodSSH / wodSSH.NET)
Hello,
I am using the following function to test for connectivity before using the client to access a remote computer. Connections are stored in a pool until ready to be used. When I run the app at normal speed, the Peek() call hangs. When I run in debug mode, stepping through the code, Peek() appears to execute normally. Can you explain what might be going on here? We just upgraded to v2.6.6 of the client. Previously, we were using v2.5.3 but this did not seem to happen. Have there been any issues with Peek()? Does this seem like a sensible use of the method?
Protocol = SSHAuto
Blocking = true
Timeout = 0
Here is the function that calls Peek():
public override void ProofOfLife()
{
if (m_ssh != null)
{
try
{
if (m_ssh.State != SSH.States.Connected)
{
throw new Exception("ProofOfLife: SSH client is not connected.");
}
m_ssh.Peek(); // hangs here when run at normal speed
}
catch
{
throw;
}
finally
{
}
}
else
{
throw new Exception("ProofOfLife: SSH client is null");
}
}
SSH.NET Peek() hangs
Hi Tony,
Peek should not hang under any circumstances. What can I do to duplicate this, exactly? Should I run several instances, or do something special?
Does this happen with some specific server, or all of them you tried with?
Jasmine.
SSH.NET Peek() hangs
I'm not sure how to tell you how to reproduce this as the app that uses the SSH client is very complex and connects to any of hundreds of remote servers. This does not happen in v2.5.3 of the client nor does it happen when I run this in the debugger - which would seem to suggest some sort of timing issue. Possibly only happens when connection is idle and there is no data to receive, i.e. DataReady = 0. Seems to work fine when there is indeed data ready to receive. This feels like some sort of boundary condition, like a null ref exception or infinite loop caused by the absence of data to receive. Does that make sense? Perhaps you can check your code or try to reproduce based on that. Remember, I also set Blocking = true and Timeout = 0. Perhaps that helps to create the scenario?
SSH.NET Peek() hangs
Hi Tony.
I double-checked the source. HELPfile is wrong. Peek will block, just like Receive, but not clear out the buffer.
So, this is normal behavior. I would rather not go into asking to change wodSSH.NET, since someone else may use Peek the way it is now. Rather, I would suggest you change your algorithm a bit.
For example, you could set Blocking = False, Peek, Blocking = True? That would not block, but would tell you if there's something on the socket. Or you could use DataReady.
Would that solve your problem?
Jasmine.
SSH.NET Peek() hangs
Jasmine,
Yes, we actually came to the same conclusion with the Blocking property and DataReady. This will resolve our issue. We just didn't expect the component to behave differently with the new version.
Tony