Skip to content

Commit

Permalink
Add retry mechanism for network time retrieval
Browse files Browse the repository at this point in the history
- Introduces a retry mechanism with 3 attempts if network time retrieval fails initially.
  • Loading branch information
peters committed May 29, 2024
1 parent 8c6917b commit daaae92
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Snap/Core/SnapNetworkTimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public SnapNetworkTimeProvider(string ntpServer, int port)
var tsc = new TaskCompletionSource<DateTime?>();
ThreadPool.QueueUserWorkItem(_ =>
{
var remainingRetries = 3;
retry:
try
{
var ntpData = new byte[48];
Expand Down Expand Up @@ -90,6 +92,11 @@ public SnapNetworkTimeProvider(string ntpServer, int port)
}
catch
{
if(--remainingRetries > 0)
{
goto retry;
}

tsc.TrySetResult(null);
}
});
Expand Down

0 comments on commit daaae92

Please sign in to comment.