- The SSH connection itself (TScSSHClient)
- a terminal session (TScSSHShell)
- a port-forwarding tunnel (TScSSHChannel)
When it detects that it has lost at least one of these, it ensures that everything else is disconnected, waits, then tries to connect again.
I must be doing something wrong because often, following the disconnection, the next TScSSHClient connect fails w/ a memory access violation error. The 2nd attempt to reconnect is usually successful. Do you see anything wrong with my logic below?
Here's the logic for connecting to the server:
Code: Select all
C3Connect:
Set HostName, Port, HostKeyName, User, Password, Authentication
Try
SSHClient.Connect
Try
SSHShell.Connect
Send a shell command, sleep for a couple of seconds
Try
SSHChannel.Connect
Except log channel exception
Except log shell exception
Except log client exception
OnDisconnect event logics:
- Shell: Disable telemetry timer & log event
- Channel: Log event
- Client: Log event
Code: Select all
Disable timer to prevent reentry
Do unrelated things
If at least a minute has passed since the last connection attempt
If either Shell or Channel isn't connected
Log it & disconnect the other
Disconnect Client
If Client isn't connected
C3Connect (see function above)
Do more unrelated things
Re-enable timer
This is a typical sequence of events in my debugging log:
Running it within the IDE, after it stops w/ the error, the Delphi call stack shows:2020-06-22 17:05:00.385 - AppLog:C3 shell disconnected
2020-06-22 17:05:00.385 - AppLog:C3 SSH disconnected
2020-06-22 17:05:02.803 - Timer1 event
2020-06-22 17:05:02.803 - Timer1 - SSH shell is disconnected; ensuring that the TN tunnel is too.
2020-06-22 17:05:02.804 - AppLog:C3TN channel disconnected
2020-06-22 17:05:02.805 - Timer1 - Disconnecting SSH connection
2020-06-22 17:05:03.006 - Timer1 before C3Connect
2020-06-22 17:06:36.233 - AppLog:C3 connection failed w/ exception: Access violation at address 00000040. Read of address 00000040
2020-06-22 17:06:36.234 - Timer1 after C3Connect
Code: Select all
Timer
C3Connect
TScSSHClient.Connect
TScSSHClient.SetConnected
Code: Select all
SetConnected
TScSSHClient.DoConnect
FreeAndNil(FConnection) -- I set a breakpoint here and traced in w/ F7
TSsh2Connection.Destroy
TSsh2Connection.Close;
FStream.Vio.Close -- this is what triggers the Access Violation