EldoS | Feel safer!

Software components for data protection, secure storage and transfer

sshserver demo fails to disconnect sessions?

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#6474
Posted: 06/02/2008 18:56:42
by nate hammond (Priority Standard support level)
Joined: 06/02/2008
Posts: 3

I am running the sshserver demo in VS 2005. Connecting to it via FileZilla. Seems to work great, but when I disconnect (or shut down filezilla), the session displayed in the list box doesn't seem to go away (maybe that's just a cumulative list) but after a while it seems to run out of connections. The audit log on the screen bottom will show the next connection as "Connection Accepted: Active connections from 2 to 20" and just keeps increasing. If I press STOP it'll start the count all over again. Even if I keep the app running and watch for a timeout of sorts.. it never happens.
#6477
Posted: 06/03/2008 00:57:28
by Eugene Mayevski (EldoS Corp.)

This is a problem of the sample application which doesn't properly detect disconnection. The developers will give more details about fixing this in the sample a bit later.


Sincerely yours
Eugene Mayevski
#6479
Posted: 06/03/2008 04:00:12
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi. Please, change SSHServer_OnReceive event handler in SSHSession.cs to the following:

Code
private void SSHServer_OnReceive(object Sender, ref byte[] Buffer, int MaxSize, out int Written)
      {
         try
         {
            if (m_Socket.Poll(100000, SelectMode.SelectRead))
            {
               Written = m_Socket.Receive(Buffer, MaxSize, SocketFlags.None);
               if (Written == 0)
               {
                  CloseSession();
               }
            }
            else
            {
               Written = 0;
            }
         }
         catch(Exception ex)
         {
            Written = 0;
                Logger.Log("Socket receive operation failed: " + ex.Message);            
            CloseSession();
         }
      }
#6485
Posted: 06/03/2008 13:25:11
by nate hammond (Priority Standard support level)
Joined: 06/02/2008
Posts: 3

that didn't work. Here's what I noticed when you reach the
"m_Socket.Receive" it goes to the CATCH, which also does a CloseSession. In
the CloseSession it eventually goes to DoSocketShutdown as below:

Code
  private void DoSocketShutdown()
  {
   try
   {
    if ((m_Socket != null) && (m_Socket.Connected))
    {
     Logger.Log("Closing the socket");
     m_Socket.Shutdown(System.Net.Sockets.SocketShutdown.Both);
     m_Socket.Close();
     m_Socket = null;

however m_Socket.Connected is FALSE so it never does the shutdown and close.
Note, even if I comment out the if check and force it to Shutdown() and
Close() it still fails.

Then I started thinking. What abot the Server.listern class. There some code
there like this:
Code
ServerListener
public void Dispose()

    //kill sockets (sessions)
    lock(m_synch)
    {
     for (int i = 0, N = m_arrSessions.Count; i < N; ++i)
     {//stop all sessions
      SSHSession session=(SSHSession)m_arrSessions[i];
      System.Diagnostics.Debug.Assert(session!=null);
      session.SessionClosed-=new
SSHSession.SessionClosedHandler(OnSessionClosed);
      session.CloseSession();
      session.Dispose();
     }

Maybe we have to go higher up to there when closing these things down. What
do you think?
#6513
Posted: 06/06/2008 04:50:57
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Hi. You are right about m_Socket.connected.
However, we made some other fixes and improvements to SSHSession.cs, so I'm attaching it, please try it and tell if disconnection problem persists, here it works ok.


[ Download ]
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.

Reply

Statistics

Topic viewed 1428 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!