aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Relay/RelayClient.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-07 19:49:03 -0600
committerJP Dillingham <jp@dillingham.me>2023-01-07 19:49:03 -0600
commit8e6e0e17edf8f958b4b5bf072491d8198d9ef64c (patch)
tree7c12350fc0f7ecdc11da8e7c86b18a126d15776e /src/slskd/Relay/RelayClient.cs
parent2c751aa3029c707f92e6323d10cb1152efb66de8 (diff)
downloadslskd-8e6e0e17edf8f958b4b5bf072491d8198d9ef64c.tar.gz
include share upload in retry loop
Diffstat (limited to 'src/slskd/Relay/RelayClient.cs')
-rw-r--r--src/slskd/Relay/RelayClient.cs54
1 files changed, 30 insertions, 24 deletions
diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs
index bb121b87..052eef79 100644
--- a/src/slskd/Relay/RelayClient.cs
+++ b/src/slskd/Relay/RelayClient.cs
@@ -150,7 +150,36 @@ namespace slskd.Relay
// retry indefinitely
await Retry.Do(
- task: () => HubConnection.StartAsync(StartCancellationTokenSource.Token),
+ task: async () => {
+ await HubConnection.StartAsync(StartCancellationTokenSource.Token);
+
+ State.SetValue(_ => TranslateState(HubConnection.State));
+ Log.Information("Relay controller connection established. Awaiting authentication...");
+
+ await LoggedInTaskCompletionSource.Task;
+
+ LoggedIn = true;
+
+ Log.Information("Authenticated. Uploading shares...");
+
+ try
+ {
+ // give the controller time to register the login; there's a race condition here
+ // that should be extremely unlikely, but i've seen it when debugging.
+ await Task.Delay(500);
+
+ await UploadSharesAsync();
+ }
+ catch (Exception ex)
+ {
+ Log.Error(ex, ex.Message);
+ Log.Error("Disconnecting from the relay controller");
+ await StopAsync();
+ throw;
+ }
+
+ Log.Information("Shares uploaded. Ready to upload files.");
+ },
isRetryable: (attempts, ex) => true,
onFailure: (attempts, ex) =>
{
@@ -160,29 +189,6 @@ namespace slskd.Relay
maxAttempts: int.MaxValue,
maxDelayInMilliseconds: 30000,
StartCancellationTokenSource.Token);
-
- State.SetValue(_ => TranslateState(HubConnection.State));
- Log.Information("Relay controller connection established. Awaiting authentication...");
-
- await LoggedInTaskCompletionSource.Task;
-
- LoggedIn = true;
-
- Log.Information("Authenticated. Uploading shares...");
-
- try
- {
- await UploadSharesAsync();
- }
- catch (Exception ex)
- {
- Log.Error(ex, ex.Message);
- Log.Error("Disconnecting from the relay controller");
- await StopAsync();
- throw;
- }
-
- Log.Information("Shares uploaded. Ready to upload files.");
}
finally
{