Fix race condition between swarm server startup and health checking

This commit is contained in:
Jordan Brown
2020-12-31 23:22:49 -05:00
parent b50ff9d569
commit a4ade2b78a
@@ -41,6 +41,11 @@ namespace Tgstation.Server.Host.Swarm
/// </summary>
const int UpdateCommitTimeoutMinutes = 10;
/// <summary>
/// Number of seconds between <see cref="forceHealthCheckTcs"/> triggering and a health check being performed.
/// </summary>
const int SecondsToDelayForcedHealthChecks = 15;
/// <summary>
/// See <see cref="JsonSerializerSettings"/> for the swarm system.
/// </summary>
@@ -1060,7 +1065,13 @@ namespace Tgstation.Server.Host.Swarm
await awakeningTask.ConfigureAwait(false);
if (!swarmController && !nextForceHealthCheckTask.IsCompleted)
if (nextForceHealthCheckTask.IsCompleted && swarmController)
{
// Intentionally wait a few seconds for the other server to start up before interogating it
logger.LogTrace("Next health check triggering in {0}s...", SecondsToDelayForcedHealthChecks);
await asyncDelayer.Delay(TimeSpan.FromSeconds(SecondsToDelayForcedHealthChecks), cancellationToken);
}
else if (!swarmController && !nextForceHealthCheckTask.IsCompleted)
{
if (!lastControllerHealthCheck.HasValue)
{