EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SimpleSSH and SimpleSFTP Open() hangs when server is down

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#13810
Posted: 07/05/2010 23:35:27
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

Hi,
We've recently moved from SBB 7 to 8 and have noticed a difference in behaviour.

Under 7, if the SSH host is down an exception is thrown. Under 8, it hangs at the Open() method. This is for both SSHSimpleClient and SFTPSimpleClient.

The problem can be reproduced in using the sample app below. When the 7.x assemblies are referenced, the exception is caught. When the 8.x assemblies are referenced the app hangs at
Code
client.Open()


I had a look at the help and couldn't see a way to set a timeout on the client object.

Is there a method or property that I can set to cause Open() throw an exception (or event) when the server is unavailable?

Cheers.

Code
static void Main(string[] args)
{
   SBUtils.Unit.SetLicenseKey("key");
   TElSimpleSSHClient client = new TElSimpleSSHClient();
   client.Address = "10.0.0.122";
   client.Username = "ben";
   client.Password = "password";
   client.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_PASSWORD;

   client.KeyStorage = new TElSSHMemoryKeyStorage();
   client.OnKeyValidate += new SBSSHCommon.TSSHKeyValidateEvent(client_OnKeyValidate);
   client.OnError += new SBSSHCommon.TSSHErrorEvent(client_OnError);

   Console.WriteLine("About to open a connection");
   try
   {
      client.Open();
      Console.WriteLine("Openned a connection");
   }
   catch (Exception e)
   {
      Console.WriteLine("Exception caught: " + e.Message);
   }            
   Console.ReadLine();

}

static void client_OnError(object Sender, int ErrorCode)
{
   Console.WriteLine("Error: " + ErrorCode);
}

static void client_OnKeyValidate(object Sender, TElSSHKey ServerKey, ref bool Validate)
{
   Validate = true;
}
#13812
Posted: 07/06/2010 02:42:38
by Ken Ivanov (EldoS Corp.)

Thank you for contacting us.

Could you please specify the exact error message you are getting with SBB7 (the message may vary depending on the environment)?

Please use the SocketTimeout property to specify connection timeout in milliseconds.
#13814
Posted: 07/06/2010 03:16:48
by Ken Ivanov (EldoS Corp.)

Please ignore my question about the error message, we were able to reproduce the problem here in our environment. The issue is being fixed at the moment. The fix will be available along with the future build update.

Meanwhile, please set SocketTimeout to a non-zero value to bypass the issue. As a matter of fact, using zero socket timeout is not a good practice, as it may lead to long-term hangups under some conditions (caused by the internals of TCP/IP).
#13829
Posted: 07/06/2010 19:37:20
by Vincent Parrett (Standard support level)
Joined: 01/17/2008
Posts: 20

Thanks for the quick response. Setting SocketTimeout is a viable work-around until the fix is available.

I have a related, but different question. From my testing it seems that if the server terminates the connection, the client.Active property remains true. The only way I've found to see if the connection is actually active is to try to use it, can catch any resulting exception.

Is there a way to force SimpleSSHClient and SimpleSFTPClient to re-evaluate the Active property?

Thanks.
#13830
Posted: 07/07/2010 00:34:18
by Ken Ivanov (EldoS Corp.)

Due to the nature of TCP/IP protocol stack, it is not possible to detect whether connection is alive without trying to send something to it or to read from it.

Your task can actually be achieved with the use of keep-alive signals. Please set the KeepAlivePeriod property to the desired period of keep-alive requests (in milliseconds). This will let the component attempt to send some data to the channel periodically and detect connection shutdown in that way.
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 1283 times

Number of guests: 2, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!