Skip to content

Commit

Permalink
long timeout first time
Browse files Browse the repository at this point in the history
  • Loading branch information
Marchhill committed Nov 6, 2024
1 parent 190c480 commit ce88616
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Nethermind/Nethermind.Shutter/ShutterP2P.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,18 @@ public async Task Start(Multiaddress[] bootnodeP2PAddresses, Func<Dto.Decryption
if (_logger.IsInfo) _logger.Info($"Started Shutter P2P: {_peer.Address}");

long lastMessageProcessed = DateTimeOffset.Now.ToUnixTimeSeconds();
bool hasTimedOut = false;

while (true)
{
try
{
using var timeoutSource = new CancellationTokenSource(TimeSpan.FromMinutes(1));
using var timeoutSource = new CancellationTokenSource(hasTimedOut ? TimeSpan.FromMinutes(1) : DisconnectionLogTimeout);
using var source = CancellationTokenSource.CreateLinkedTokenSource(_cts.Token, timeoutSource.Token);

byte[] msg = await _msgQueue.Reader.ReadAsync(source.Token);
lastMessageProcessed = DateTimeOffset.Now.ToUnixTimeSeconds();
hasTimedOut = false;
ProcessP2PMessage(msg, onKeysReceived);
}
catch (OperationCanceledException)
Expand All @@ -116,11 +119,15 @@ public async Task Start(Multiaddress[] bootnodeP2PAddresses, Func<Dto.Decryption
if (_logger.IsInfo) _logger.Info($"Shutting down Shutter P2P...");
break;
}
else if (_logger.IsWarn)
else
{
long delta = DateTimeOffset.Now.ToUnixTimeSeconds() - lastMessageProcessed;
if (delta > DisconnectionLogTimeout.TotalSeconds)
_logger.Warn($"Not receiving Shutter messages ({delta / 60}m)...");
hasTimedOut = true;
if (_logger.IsWarn)
{
long delta = DateTimeOffset.Now.ToUnixTimeSeconds() - lastMessageProcessed;
if (delta >= DisconnectionLogTimeout.TotalSeconds)
_logger.Warn($"Not receiving Shutter messages ({delta / 60}m)...");
}
}
}
catch (Exception e)
Expand Down

0 comments on commit ce88616

Please sign in to comment.