Changes Ssh client autoreconnect method to null client and start with new client on next attempt. Saw issues specifically with Polycom not reconnecting unless we spin up a new client.

This commit is contained in:
Alex Johnson
2020-01-21 09:51:16 -05:00
parent 33f2814ecf
commit 19263590a7

View File

@@ -207,25 +207,24 @@ namespace PepperDash.Core
return; return;
} }
// This handles both password and keyboard-interactive (like on OS-X, 'nixes)
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(Username);
kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(kauth_AuthenticationPrompt);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password);
if (Client != null) if (Client != null)
{ {
Debug.Console(1, this, "Cleaning up disconnected client"); Debug.Console(1, this, "Cleaning up disconnected client");
Client.ErrorOccurred -= Client_ErrorOccurred; Client.ErrorOccurred -= Client_ErrorOccurred;
KillStream(); KillStream();
Client.Disconnect();
} }
else
Debug.Console(1, this, "Creating new SshClient");
ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
if (Client == null)
{ {
// This handles both password and keyboard-interactive (like on OS-X, 'nixes)
KeyboardInteractiveAuthenticationMethod kauth = new KeyboardInteractiveAuthenticationMethod(Username);
kauth.AuthenticationPrompt += new EventHandler<AuthenticationPromptEventArgs>(kauth_AuthenticationPrompt);
PasswordAuthenticationMethod pauth = new PasswordAuthenticationMethod(Username, Password);
Debug.Console(1, this, "Creating new SshClient");
ConnectionInfo connectionInfo = new ConnectionInfo(Hostname, Port, Username, pauth, kauth);
Client = new SshClient(connectionInfo); Client = new SshClient(connectionInfo);
} }
Client.ErrorOccurred -= Client_ErrorOccurred; Client.ErrorOccurred -= Client_ErrorOccurred;
Client.ErrorOccurred += Client_ErrorOccurred; Client.ErrorOccurred += Client_ErrorOccurred;
@@ -298,9 +297,13 @@ namespace PepperDash.Core
/// </summary> /// </summary>
void HandleConnectionFailure() void HandleConnectionFailure()
{ {
if (Client != null) if (Client != null)
Client.Disconnect(); {
Client.Disconnect();
Client = null;
}
KillStream(); KillStream();
Debug.Console(2, this, "Client nulled due to connection failure. AutoReconnect: {0}, ConnectEnabled: {1}", AutoReconnect, ConnectEnabled);
if (AutoReconnect && ConnectEnabled) if (AutoReconnect && ConnectEnabled)
{ {
@@ -418,8 +421,11 @@ namespace PepperDash.Core
{ {
try try
{ {
TheStream.Write(text); if (Client != null)
TheStream.Flush(); {
TheStream.Write(text);
TheStream.Flush();
}
} }
catch catch
{ {
@@ -433,8 +439,11 @@ namespace PepperDash.Core
{ {
try try
{ {
TheStream.Write(bytes, 0, bytes.Length); if (Client != null)
TheStream.Flush(); {
TheStream.Write(bytes, 0, bytes.Length);
TheStream.Flush();
}
} }
catch catch
{ {