EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to prematurely abort/close a TElCommandSSHTunnel

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.
#30670
Posted: 09/10/2014 15:10:21
by Charles DeWeese (Standard support level)
Joined: 04/17/2008
Posts: 52

How do I prematurely abort a command in process executed via a TElCommandSSHTunnel connection tunnel or simply close the tunnel without disconnecting the main SSHClient connection?

Everything I've tried either closes the main SSHClient connection or I get a Invalid Packet error.

I've read the documents and searched the website but I can't seem to find anything
#30671
Posted: 09/10/2014 15:58:58
by Ken Ivanov (EldoS Corp.)

Hi Charles,

The correct way of closing an individual tunneled connection is to call the Close() method of the appropriate TElSSHTunnelConnection object.

Ken
#30673
Posted: 09/10/2014 21:10:50
by Charles DeWeese (Standard support level)
Joined: 04/17/2008
Posts: 52

Thank you,

The TESSHTunnelConnection.OnClose event gets fired immediately, this was not obvious until I reviewed the source code. (that fact lead to some problems with my code, so I revised it)

TElCommandSSHTunnel.OnClose appears to fire after the tunnel has been torn down, but not completely? I set a flag indicating the finished and then in another routine check the finished flag and if set free and nil the TElCommandSSHTunnel.

This was randomly leading to either a SSH Error: Invalid Packet and in some rare cases an A/V because the TElCommandSSHTunnel was freed prematurely.

My solution (which appears to be working flawlessly) is to check the TElCommandSSHTunnel.ConnectionCount and wait for it to equal 0 before freeing the TElCommandSSHTunnel object.
#30679
Posted: 09/11/2014 02:54:20
by Ken Ivanov (EldoS Corp.)

Hi Charles,

Your solution is correct. Shutdown of a tunneled connection requires some interaction between the client and the server. The Close() call only initiates the shutdown operation asynchronously. It does not result in immediate closure of the connection, which remains in a 'half-alive' state for a little while. So you actually do have to wait a little until the connection and all the associated resources are freed before releasing the parent TElCommandSSHTunnel object. Waiting for ConnectionCount to go down to 0 is one of the options. Another option is to leave the TElCommandSSHTunnel alive until the main SSH connection is closed, and release it together with TElSSHClient object.

Ken

Reply

Statistics

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