From c6c9b6f4f9a0b6ad53cd1181ccf38210c2b7a85b Mon Sep 17 00:00:00 2001 From: Nick Blakely Date: Tue, 11 Aug 2020 22:15:13 -0700 Subject: [PATCH] Fix heartbeats being ignored. --- Giants.Services/Store/CosmosDbServerRegistryStore.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Giants.Services/Store/CosmosDbServerRegistryStore.cs b/Giants.Services/Store/CosmosDbServerRegistryStore.cs index adee78f..969e7d6 100644 --- a/Giants.Services/Store/CosmosDbServerRegistryStore.cs +++ b/Giants.Services/Store/CosmosDbServerRegistryStore.cs @@ -20,6 +20,8 @@ private readonly IDateTimeProvider dateTimeProvider; private readonly TimeSpan timeoutPeriod; private CosmosDbClient client; + + private const int ServerRefreshIntervalInMinutes = 1; public CosmosDbServerRegistryStore( ILogger logger, @@ -104,7 +106,12 @@ if (allServerInfo.ContainsKey(serverInfo.HostIpAddress)) { - if (allServerInfo[serverInfo.HostIpAddress].Equals(serverInfo)) + ServerInfo existingServerInfo = allServerInfo[serverInfo.HostIpAddress]; + + // DDOS protection: skip write to Cosmos if parameters have not changed, + // or it's not been long enough. + if (existingServerInfo.Equals(serverInfo) + && Math.Abs((existingServerInfo.LastHeartbeat - serverInfo.LastHeartbeat).TotalMinutes) < ServerRefreshIntervalInMinutes) { this.logger.LogInformation("State for {IPAddress} is unchanged. Skipping write to store.", serverInfo.HostIpAddress); return;