mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-08-31 10:58:28 +00:00
Merge pull request #1469 from PepperDash/hotfix/ssh-stopprog-timing
fix(core-ssh): stop reconnect loop during stopprog
This commit is contained in:
commit
7f05654638
1 changed files with 23 additions and 11 deletions
|
|
@ -151,6 +151,8 @@ namespace PepperDash.Core
|
||||||
// Thread-safety lock for state changes
|
// Thread-safety lock for state changes
|
||||||
private readonly object _stateLock = new object();
|
private readonly object _stateLock = new object();
|
||||||
|
|
||||||
|
private volatile bool _isProgramStopping;
|
||||||
|
|
||||||
private bool disconnectLogged = false;
|
private bool disconnectLogged = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -207,11 +209,9 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
if (programEventType == eProgramStatusEventType.Stopping)
|
if (programEventType == eProgramStatusEventType.Stopping)
|
||||||
{
|
{
|
||||||
if (client != null)
|
_isProgramStopping = true;
|
||||||
{
|
this.LogDebug("Program stopping. Closing connection");
|
||||||
this.LogDebug("Program stopping. Closing connection");
|
Disconnect();
|
||||||
Disconnect();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -228,6 +228,12 @@ namespace PepperDash.Core
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_isProgramStopping)
|
||||||
|
{
|
||||||
|
this.LogDebug("Skipping connect because program is stopping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ConnectEnabled = true;
|
ConnectEnabled = true;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -308,7 +314,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
disconnectLogged = true;
|
disconnectLogged = true;
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
if (AutoReconnect)
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {autoReconnect}, {autoReconnectInterval}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {autoReconnect}, {autoReconnectInterval}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
StartReconnectTimer();
|
StartReconnectTimer();
|
||||||
|
|
@ -320,7 +326,7 @@ namespace PepperDash.Core
|
||||||
|
|
||||||
disconnectLogged = true;
|
disconnectLogged = true;
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
if (AutoReconnect)
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
StartReconnectTimer();
|
StartReconnectTimer();
|
||||||
|
|
@ -332,7 +338,7 @@ namespace PepperDash.Core
|
||||||
this.LogVerbose(e, "Exception details: ");
|
this.LogVerbose(e, "Exception details: ");
|
||||||
disconnectLogged = true;
|
disconnectLogged = true;
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
if (AutoReconnect)
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
StartReconnectTimer();
|
StartReconnectTimer();
|
||||||
|
|
@ -467,7 +473,7 @@ namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
connectLock.Release();
|
connectLock.Release();
|
||||||
}
|
}
|
||||||
if (AutoReconnect && ConnectEnabled)
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
{
|
{
|
||||||
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
this.LogDebug("Checking autoreconnect: {0}, {1}ms", AutoReconnect, AutoReconnectIntervalMs);
|
||||||
StartReconnectTimer();
|
StartReconnectTimer();
|
||||||
|
|
@ -510,7 +516,10 @@ namespace PepperDash.Core
|
||||||
this.LogError("ObjectDisposedException sending '{message}'. Restarting connection...", text.Trim());
|
this.LogError("ObjectDisposedException sending '{message}'. Restarting connection...", text.Trim());
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
StartReconnectTimer();
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
|
{
|
||||||
|
StartReconnectTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -543,7 +552,10 @@ namespace PepperDash.Core
|
||||||
this.LogException(ex, "ObjectDisposedException sending {message}", ComTextHelper.GetEscapedText(bytes));
|
this.LogException(ex, "ObjectDisposedException sending {message}", ComTextHelper.GetEscapedText(bytes));
|
||||||
|
|
||||||
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
KillClient(SocketStatus.SOCKET_STATUS_CONNECT_FAILED);
|
||||||
StartReconnectTimer();
|
if (AutoReconnect && ConnectEnabled && !_isProgramStopping)
|
||||||
|
{
|
||||||
|
StartReconnectTimer();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue