EldoS | Feel safer!

Software components for data protection, secure storage and transfer

SFTP Intermittent problem setting license key - Class not registered

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#27547
Posted: 12/03/2013 01:04:58
by Eugene Mayevski (EldoS Corp.)

Thank you.

The call stack doesn't show SecureBlackbox is involved, so it seems that your code needs extra review and improvement in regards to error handling. Indeed half-opened sockets are evil that can lead to shortage in socket resources (socket handle table is limited in size) and this in turn can cause different kinds of troubles.

So the original problem can be postponed until you solve these crashes problem. We must wait in order to exclude the factor of crashes from the original problem.


Sincerely yours
Eugene Mayevski
#27554
Posted: 12/03/2013 16:40:37
by Brett Beattie (Standard support level)
Joined: 03/08/2011
Posts: 25

Thanks Eugene,

Can you provide some advice on what I can do with the offending code? The following function (based on the eldos sample code) is where the socket error is thrown. I guess if I catch a SocketException I can handle it somehow? Log it and then try starting to poll again? Do I need to and/or can I clean up the socket handles?
Thanks

Code
private void ReadThread()
    {
      try
      {
        _serviceError = false;
        Monitor.Enter(_processLock);
        if (_serviceSSHServer != null)
        {
          try
          {
            //open a connection
            _serviceSSHServer.Open();
          }
          finally
          {
            Monitor.Exit(_processLock);
          }
          while ((_netSocket != null) && (_netSocket.Connected) && (!_serviceError))
          {
            if (_netSocket.Poll(1000000, SelectMode.SelectRead))
            {
              Monitor.Enter(_processLock);
              try
              {
                if (_serviceSSHServer == null)
                {
                  break;
                }
                else
                {
                  //flag that data has arrived
                  _serviceSSHServer.DataAvailable();
                }
              }
              finally
              {
                Monitor.Exit(_processLock);
              }
              Thread.Sleep(0);
            }
            else
            {
              Thread.Sleep(50);
            }
          }
        }
      }
      catch (Exception ex)
      {
        if (!(ex is ThreadAbortException))
        {
          Logger.Log("ReadThread : " + ex.Message, false);
          CloseSession();
          throw;
        }
        else
        {
          if (this.SessionClosed != null)
          {
            this.SessionClosed(this, null);
            _serviceThread = null;
          }
        }
      }
    }
#27557
Posted: 12/04/2013 02:16:43
by Eugene Mayevski (EldoS Corp.)

I would rewrite the catch statement. First you don't need to re-throw the exception - if you do, you get an unhandled exception and your service crashes. Next, you must close the session in all cases, i.e. you should not exclude ThreadAbortException from processing.

On a side note please use CODE button to mark the beginning and the end of the code block in your messages.


Sincerely yours
Eugene Mayevski

Reply

Statistics

Topic viewed 2766 times

Number of guests: 1, 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!