diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-06-11 15:50:45 -0500 |
|---|---|---|
| committer | JP Dillingham <jpdillingham@gmail.com> | 2021-06-11 15:50:45 -0500 |
| commit | 07331bd2d16bfba8d3d0365d1e7860e807ba6d30 (patch) | |
| tree | c249ca23515b0aedc66dd242f1b8088cac4105eb /src/slskd/Core | |
| parent | 94865acdf168cb11fb1e28c3a50673611ecfc369 (diff) | |
| download | slskd-07331bd2d16bfba8d3d0365d1e7860e807ba6d30.tar.gz | |
simplify exponential backoff logic
Diffstat (limited to 'src/slskd/Core')
| -rw-r--r-- | src/slskd/Core/Service.cs | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/slskd/Core/Service.cs b/src/slskd/Core/Service.cs index 4c1d2a4f..a8324a75 100644 --- a/src/slskd/Core/Service.cs +++ b/src/slskd/Core/Service.cs @@ -38,9 +38,7 @@ namespace slskd public class Service : IHostedService { - private static readonly int ReconnectDelaySeconds = 1; - private static readonly int ReconnectMaxDelaySeconds = 300; // 5 minutes - private static readonly int ReconnectBackoffRate = 2; + private static readonly int ReconnectMaxDelayMilliseconds = 300000; // 5 minutes private static int reconnectAttempts = 0; private static (int Directories, int Files) sharedCounts = (0, 0); @@ -232,14 +230,12 @@ namespace slskd } else { - var delay = Compute.ExponentialBackoffDelay( + var (delay, jitter) = Compute.ExponentialBackoffDelay( iteration: reconnectAttempts, - backoffRate: ReconnectBackoffRate, - delayInSeconds: ReconnectDelaySeconds, - maxDelayInSeconds: ReconnectMaxDelaySeconds); + maxDelayInMilliseconds: ReconnectMaxDelayMilliseconds); - Logger.Information($"Waiting {delay} second(s) before reconnecting..."); - await Task.Delay(delay * 1000); + Logger.Information($"Waiting {delay + jitter} millisecond(s) before reconnecting..."); + await Task.Delay(delay + jitter); Interlocked.Increment(ref reconnectAttempts); |
