aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Transfers/Downloads/DownloadService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/slskd/Transfers/Downloads/DownloadService.cs')
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index cb9423bc..5a5fe699 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -722,9 +722,9 @@ namespace slskd.Transfers.Downloads
var transfer = context.Transfers.Find(id);
- if (transfer == default)
+ if (transfer == default || transfer.Direction != TransferDirection.Download)
{
- throw new NotFoundException($"No download matching id ${id}");
+ throw new NotFoundException($"No download matching id {id}");
}
var place = await Client.GetDownloadPlaceInQueueAsync(transfer.Username, transfer.Filename);
@@ -1059,6 +1059,12 @@ namespace slskd.Transfers.Downloads
t.EndedAt ??= DateTime.UtcNow;
+ // Retry.Do() wraps failures in an AggregateException; use the most recent so that the state reflects what happened
+ if (exception is AggregateException aggregate && aggregate.InnerExceptions.Count > 0)
+ {
+ exception = aggregate.InnerExceptions.Last();
+ }
+
// Soulseek.NET will include the filename and username in some messages; this is useful for many things but not tracking
// exceptions in a database. when we encounter one of these, drop the first segment.
var m = exception.Message;
@@ -1070,6 +1076,7 @@ namespace slskd.Transfers.Downloads
{
OperationCanceledException => TransferStates.Cancelled,
TimeoutException => TransferStates.TimedOut,
+ TransferRejectedException => TransferStates.Rejected,
_ => TransferStates.Errored,
};
}
@@ -1221,20 +1228,6 @@ namespace slskd.Transfers.Downloads
transfer.EnqueuedAt ??= DateTime.UtcNow;
}
- // important! the transfer on the Soulseek.NET side may have completed, but the slskd transfer
- // *might* still have remaining retry attempts. leave this non-committal for now, and allow
- // the final update after all retry attempts have been exhausted to add it.
- // this means that the ONLY way to check whether a transfer is really 'dead' inclusive of all
- // retries is to look for this flag
- if (args.Transfer.State.HasFlag(TransferStates.Completed)
- && !args.Transfer.State.HasFlag(TransferStates.Succeeded)
- && transfer.Attempts < retryOptions.Attempts)
- {
- transfer.State = TransferStates.Queued | TransferStates.Locally;
- }
-
- transfer = transfer.WithSoulseekTransfer(args.Transfer);
-
Telemetry.Metrics.Update(() =>
{
if (!TransferStateCategories.Queued.Contains(args.PreviousState) && TransferStateCategories.Queued.Contains(transfer.State))
@@ -1254,6 +1247,18 @@ namespace slskd.Transfers.Downloads
stateHistory.Add(transfer.State);
+ // important! the transfer on the Soulseek.NET side may have completed, but the slskd transfer
+ // *might* still have remaining retry attempts. leave this non-committal for now, and allow
+ // the final update after all retry attempts have been exhausted to add it.
+ // this means that the ONLY way to check whether a transfer is really 'dead' inclusive of all
+ // retries is to look for this flag
+ if (args.Transfer.State.HasFlag(TransferStates.Completed)
+ && !args.Transfer.State.HasFlag(TransferStates.Succeeded)
+ && transfer.Attempts < retryOptions.Attempts)
+ {
+ transfer.State = TransferStates.Queued | TransferStates.Locally;
+ }
+
// todo: broadcast
SynchronizedUpdate(transfer, semaphore: updateSyncRoot, cancellationToken: cancellationToken);
}
@@ -1553,11 +1558,10 @@ namespace slskd.Transfers.Downloads
{
Log.Error(ex, "Download of {Filename} from user {Username} failed: {Message}", transfer.Filename, transfer.Username, ex.Message);
- TryFail(transfer.Id, exception: ex);
-
- // todo: broadcast
SynchronizedUpdate(transfer, semaphore: updateSyncRoot, cancellationToken: CancellationToken.None);
+ TryFail(transfer.Id, exception: ex);
+ // todo: broadcast transfer state to a hub
Telemetry.Metrics.Update(() =>
{
Telemetry.Metrics.Transfers.Downloads.Completed.Failed.Inc(1);
@@ -1569,11 +1573,10 @@ namespace slskd.Transfers.Downloads
{
Log.Error(ex, "Download of {Filename} from user {Username} failed: {Message}", transfer.Filename, transfer.Username, ex.Message);
- TryFail(transfer.Id, exception: ex);
-
- // todo: broadcast
SynchronizedUpdate(transfer, semaphore: updateSyncRoot, cancellationToken: CancellationToken.None);
+ TryFail(transfer.Id, exception: ex);
+ // todo: broadcast transfer state to a hub
Telemetry.Metrics.Update(() =>
{
Telemetry.Metrics.Transfers.Downloads.Completed.Failed.Inc(1);