From bbfd8de4468bc3e68ea5099e89b9bdad966fa4d8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 5 Nov 2022 12:45:12 -0500 Subject: reconnect client indefinitely --- src/slskd/Network/NetworkClient.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/slskd/Network/NetworkClient.cs b/src/slskd/Network/NetworkClient.cs index 30cc6971..c3ae9365 100644 --- a/src/slskd/Network/NetworkClient.cs +++ b/src/slskd/Network/NetworkClient.cs @@ -418,14 +418,7 @@ namespace slskd.Network return message; }; }) - .WithAutomaticReconnect(new[] - { - TimeSpan.FromSeconds(0), - TimeSpan.FromSeconds(1), - TimeSpan.FromSeconds(3), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(30), - }) + .WithAutomaticReconnect(new ControllerRetryPolicy(0, 1, 3, 10, 30, 60)) .Build(); HubConnection.Reconnected += HubConnection_Reconnected; @@ -453,5 +446,20 @@ namespace slskd.Network SyncRoot.Release(); } } + + private class ControllerRetryPolicy : IRetryPolicy + { + public ControllerRetryPolicy(params int[] intervals) + { + Intervals = intervals; + } + + private int[] Intervals { get; set; } + + public TimeSpan? NextRetryDelay(RetryContext retryContext) + { + return TimeSpan.FromSeconds(Intervals[Math.Min(retryContext.PreviousRetryCount, Intervals.Length - 1)]); + } + } } } -- cgit v1.2.3