aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-01-08 16:00:17 -0600
committerJP Dillingham <jp@dillingham.me>2023-01-08 16:00:17 -0600
commit520482de72f2844c09c4b18e7d9790d549257fa6 (patch)
tree4a79de977591f38557262d23a5416e488dfda27f /src
parent0733f863b1fbd0c1e06f72de21b0370caee4923f (diff)
downloadslskd-520482de72f2844c09c4b18e7d9790d549257fa6.tar.gz
make upload more resilient to auth timing
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Relay/RelayClient.cs24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/slskd/Relay/RelayClient.cs b/src/slskd/Relay/RelayClient.cs
index 6f6f5428..dabde123 100644
--- a/src/slskd/Relay/RelayClient.cs
+++ b/src/slskd/Relay/RelayClient.cs
@@ -550,16 +550,32 @@ namespace slskd.Relay
var temp = Path.Combine(Path.GetTempPath(), Program.AppName, $"share_backup_{Path.GetRandomFileName()}.db");
- Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Program.AppName));
-
try
{
Log.Debug("Backing up shares to {Filename}", temp);
+
+ Directory.CreateDirectory(Path.GetDirectoryName(temp));
+
await Shares.DumpAsync(temp);
- Log.Debug("Share backup successful");
+ Log.Debug("Share backup successful");
Log.Debug("Requesting share upload token...");
- var token = await HubConnection.InvokeAsync<Guid>(nameof(RelayHub.BeginShareUpload));
+
+ Guid token = Guid.Empty;
+
+ // retry this a few times. it can throw if a race condition materializes
+ // between this logic and the authentication flow, and it'll almost certainly be
+ // worked out properly if we just wait a second and try again
+ await Retry.Do(task: async () =>
+ {
+ token = await HubConnection.InvokeAsync<Guid>(nameof(RelayHub.BeginShareUpload));
+ },
+ isRetryable: (_, _) => true,
+ onFailure: (count, ex) => Log.Warning("Failed attempt #{Attempts} to obtain share upload token: {Message}", count, ex.Message),
+ maxAttempts: 3,
+ maxDelayInMilliseconds: 5000,
+ cancellationToken);
+
Log.Debug("Share upload token {Token}", token);
var stream = new FileStream(temp, FileMode.Open, FileAccess.Read);