From 9bff52c48d333f8b8d7d5e227d28d65628b1c0a7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Oct 2025 18:49:50 -0500 Subject: add sync update at class level --- src/slskd/Transfers/Downloads/DownloadService.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index a462f3de..9a64c386 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -1014,5 +1014,19 @@ namespace slskd.Transfers.Downloads context.Update(transfer); context.SaveChanges(); } + + private void SynchronizedUpdate(Transfer transfer, SemaphoreSlim semaphore, CancellationToken cancellationToken = default) + { + semaphore.Wait(cancellationToken); + + try + { + Update(transfer); + } + finally + { + semaphore.Release(); + } + } } } \ No newline at end of file -- cgit v1.2.3 From dba88b05e9433f7726bacfd1f1fc48c394c7aadb Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Oct 2025 18:50:20 -0500 Subject: use sync update --- src/slskd/Transfers/Downloads/DownloadService.cs | 27 ++++++------------------ 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 9a64c386..3bc3d6af 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -201,21 +201,8 @@ namespace slskd.Transfers.Downloads public async Task DownloadAsync(Transfer transfer, Action stateChanged = null, CancellationToken cancellationToken = default) { var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); - var syncRoot = new SemaphoreSlim(1, 1); - - void SynchronizedUpdate(Transfer transfer, bool cancellable = true) - { - syncRoot.Wait(cancellable ? cts.Token : CancellationToken.None); - - try - { - Update(transfer); - } - finally - { - syncRoot.Release(); - } - } + var updateSemaphore = new SemaphoreSlim(1, 1); + var progressSemaphore = new SemaphoreSlim(1, 1); var lockName = $"{nameof(DownloadAsync)}:{transfer.Username}:{transfer.Filename}"; @@ -277,7 +264,7 @@ namespace slskd.Transfers.Downloads // instead, allow these to be left "hanging" so that they are properly cleaned up at the next startup if (Application.IsShuttingDown) { - Log.Debug("Download update of {Filename} to {Username} not persisted; app is shutting down", transfer.Filename, transfer.Username); + Log.Debug("Download update of {Filename} from {Username} not persisted; app is shutting down", transfer.Filename, transfer.Username); return; } @@ -291,7 +278,7 @@ namespace slskd.Transfers.Downloads } // todo: broadcast - SynchronizedUpdate(transfer); + SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: cts.Token); } finally { @@ -365,7 +352,7 @@ namespace slskd.Transfers.Downloads transfer = transfer.WithSoulseekTransfer(completedTransfer); // todo: broadcast to signalr hub - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); // move the file from incomplete to complete var destinationDirectory = System.IO.Path.GetDirectoryName(transfer.Filename.ToLocalFilename(baseDirectory: OptionsMonitor.CurrentValue.Directories.Downloads)); @@ -434,7 +421,7 @@ namespace slskd.Transfers.Downloads }; // todo: broadcast - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); throw; } @@ -447,7 +434,7 @@ namespace slskd.Transfers.Downloads transfer.State = TransferStates.Completed | TransferStates.Errored; // todo: broadcast - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); throw; } -- cgit v1.2.3 From 78a9e94a4bfd5e67e0751fe573ef948790020eae Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 11 Oct 2025 18:50:35 -0500 Subject: don't update progress if previous update still pending --- src/slskd/Transfers/Downloads/DownloadService.cs | 38 ++++++++++++++---------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 3bc3d6af..6a60c836 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -292,28 +292,36 @@ namespace slskd.Transfers.Downloads // being made after the transfer is completed, causing them to appear 'stuck' if (transfer.State == TransferStates.InProgress) { - syncRoot.Wait(cts.Token); - - try + // don't wait for the semaphore; if a previous progress update is still hanging, don't make + // the problem worse. this will result in fewer/jumpy updates on systems with slow filesystems + // but the alternative is to continue to stack slow writes on top of one another + if (progressSemaphore.Wait(millisecondsTimeout: 0, cts.Token)) { - // check again to see if the state changed while we were waiting to obtain the lock - if (transfer.State == TransferStates.InProgress) + try { - // update only the properties that we expect to change between progress updates - // this helps prevent this update from 'stepping' on other updates - transfer.BytesTransferred = args.Transfer.BytesTransferred; - transfer.AverageSpeed = args.Transfer.AverageSpeed; + // check again to see if the state changed while we were waiting to obtain the lock + if (transfer.State == TransferStates.InProgress) + { + // update only the properties that we expect to change between progress updates + // this helps prevent this update from 'stepping' on other updates + transfer.BytesTransferred = args.Transfer.BytesTransferred; + transfer.AverageSpeed = args.Transfer.AverageSpeed; - using var context = ContextFactory.CreateDbContext(); + using var context = ContextFactory.CreateDbContext(); - context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter - .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) - .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); + } + } + finally + { + progressSemaphore.Release(); } } - finally + else { - syncRoot.Release(); + Log.Debug("Skipped progress update of {Filename} from {Username} {BytesTransferred}/{TotalBytes}; previous update still pending", transfer.Filename, transfer.Username, args.Transfer.BytesTransferred, args.Transfer.Size); } } }), -- cgit v1.2.3 From 339641fb463420fa331fad3793885d7af83d27a9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 13:18:07 -0500 Subject: add a concurrency limit to RateLimiter --- src/slskd/Common/RateLimiter.cs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/slskd/Common/RateLimiter.cs b/src/slskd/Common/RateLimiter.cs index 8a7a63c6..b57c2f88 100644 --- a/src/slskd/Common/RateLimiter.cs +++ b/src/slskd/Common/RateLimiter.cs @@ -19,6 +19,7 @@ namespace slskd { using System; using System.ComponentModel; + using System.Threading; /// /// Ensures a minimum interval between successive invocations of a delegate. @@ -29,8 +30,11 @@ namespace slskd /// Initializes a new instance of the class. /// /// The minimum interval between invocations. + /// + /// Limit the number of concurrent executions of the specified action, in cases where the logic runs slower than the configured interval. Set this to null to remove the limit. + /// /// A value indicating whether pending action(s) should be executed during disposal. - public RateLimiter(int interval, bool flushOnDispose = false) + public RateLimiter(int interval, int? concurrencyLimit = 1, bool flushOnDispose = false) { Timer = new System.Timers.Timer(interval) { @@ -40,6 +44,11 @@ namespace slskd Timer.Elapsed += Timer_Elapsed; FlushOnDispose = flushOnDispose; + + if (concurrencyLimit.HasValue) + { + ConcurrentExecutionPreventionSemaphore = new SemaphoreSlim(concurrencyLimit.Value, concurrencyLimit.Value); + } } private bool Disposed { get; set; } @@ -47,6 +56,7 @@ namespace slskd private bool Init { get; set; } private Action Staged { get; set; } private System.Timers.Timer Timer { get; set; } + private SemaphoreSlim ConcurrentExecutionPreventionSemaphore { get; } = null; /// /// Releases all resources used by the . @@ -102,8 +112,18 @@ namespace slskd private void Timer_Elapsed(object sender, EventArgs args) { - Staged?.Invoke(); - Staged = null; + if (ConcurrentExecutionPreventionSemaphore?.Wait(0) ?? true) + { + try + { + Staged?.Invoke(); + Staged = null; + } + finally + { + ConcurrentExecutionPreventionSemaphore?.Release(); + } + } } } } \ No newline at end of file -- cgit v1.2.3 From 7cdba8bcfbaace65db333def290c7be928f76eed Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 13:18:34 -0500 Subject: switch back to shared syncRoot --- src/slskd/Transfers/Downloads/DownloadService.cs | 27 ++++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 6a60c836..4c70bca5 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -201,8 +201,7 @@ namespace slskd.Transfers.Downloads public async Task DownloadAsync(Transfer transfer, Action stateChanged = null, CancellationToken cancellationToken = default) { var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); - var updateSemaphore = new SemaphoreSlim(1, 1); - var progressSemaphore = new SemaphoreSlim(1, 1); + var syncRoot = new SemaphoreSlim(1, 1); var lockName = $"{nameof(DownloadAsync)}:{transfer.Username}:{transfer.Filename}"; @@ -251,7 +250,7 @@ namespace slskd.Transfers.Downloads Log.Information("Initializing download of {Filename} from {Username}", transfer.Filename, transfer.Username); - using var rateLimiter = new RateLimiter(250, flushOnDispose: true); + using var rateLimiter = new RateLimiter(250, concurrencyLimit: 1, flushOnDispose: true); var topts = new TransferOptions( stateChanged: (args) => @@ -278,7 +277,7 @@ namespace slskd.Transfers.Downloads } // todo: broadcast - SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: cts.Token); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: cts.Token); } finally { @@ -295,18 +294,18 @@ namespace slskd.Transfers.Downloads // don't wait for the semaphore; if a previous progress update is still hanging, don't make // the problem worse. this will result in fewer/jumpy updates on systems with slow filesystems // but the alternative is to continue to stack slow writes on top of one another - if (progressSemaphore.Wait(millisecondsTimeout: 0, cts.Token)) + if (syncRoot.Wait(millisecondsTimeout: 0, cts.Token)) { try { + // update only the properties that we expect to change between progress updates + // this helps prevent this update from 'stepping' on other updates + transfer.BytesTransferred = args.Transfer.BytesTransferred; + transfer.AverageSpeed = args.Transfer.AverageSpeed; + // check again to see if the state changed while we were waiting to obtain the lock if (transfer.State == TransferStates.InProgress) { - // update only the properties that we expect to change between progress updates - // this helps prevent this update from 'stepping' on other updates - transfer.BytesTransferred = args.Transfer.BytesTransferred; - transfer.AverageSpeed = args.Transfer.AverageSpeed; - using var context = ContextFactory.CreateDbContext(); context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter @@ -316,7 +315,7 @@ namespace slskd.Transfers.Downloads } finally { - progressSemaphore.Release(); + syncRoot.Release(); } } else @@ -360,7 +359,7 @@ namespace slskd.Transfers.Downloads transfer = transfer.WithSoulseekTransfer(completedTransfer); // todo: broadcast to signalr hub - SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); // move the file from incomplete to complete var destinationDirectory = System.IO.Path.GetDirectoryName(transfer.Filename.ToLocalFilename(baseDirectory: OptionsMonitor.CurrentValue.Directories.Downloads)); @@ -429,7 +428,7 @@ namespace slskd.Transfers.Downloads }; // todo: broadcast - SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); throw; } @@ -442,7 +441,7 @@ namespace slskd.Transfers.Downloads transfer.State = TransferStates.Completed | TransferStates.Errored; // todo: broadcast - SynchronizedUpdate(transfer, semaphore: updateSemaphore, cancellationToken: CancellationToken.None); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); throw; } -- cgit v1.2.3 From 1fe11a21c69c90c83ec78da3095f1cc1b22523a5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 13:18:57 -0500 Subject: bail out of progress update if semaphore can't be obtained immediately --- src/slskd/Transfers/Uploads/UploadService.cs | 45 ++++++++++++++++------------ 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 89700eba..037438cf 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -220,7 +220,6 @@ namespace slskd.Transfers.Uploads /// Thrown if the specified file can't be found on disk. public async Task UploadAsync(Transfer transfer) { - var cts = new CancellationTokenSource(); var syncRoot = new SemaphoreSlim(1, 1); @@ -307,7 +306,7 @@ namespace slskd.Transfers.Uploads // can throw NotFoundException (host, localFilename, localFileLength) = await ResolveFileInfoAsync(remoteFilename: transfer.Filename); - using var rateLimiter = new RateLimiter(250, flushOnDispose: true); + using var rateLimiter = new RateLimiter(250, concurrencyLimit: 1, flushOnDispose: true); var topts = new TransferOptions( stateChanged: (args) => @@ -334,28 +333,36 @@ namespace slskd.Transfers.Uploads // being made after the transfer is completed, causing them to appear 'stuck' if (transfer.State == TransferStates.InProgress) { - syncRoot.Wait(cts.Token); - - try + // don't wait for the semaphore; if a previous progress update is still hanging, don't make + // the problem worse. this will result in fewer/jumpy updates on systems with slow filesystems + // but the alternative is to continue to stack slow writes on top of one another + if (syncRoot.Wait(millisecondsTimeout: 0, cts.Token)) { - // update only the properties that we expect to change between progress updates - // this helps prevent this update from 'stepping' on other updates - transfer.BytesTransferred = args.Transfer.BytesTransferred; - transfer.AverageSpeed = args.Transfer.AverageSpeed; - - // check again to see if the state changed while we were waiting to obtain the lock - if (transfer.State == TransferStates.InProgress) + try { - using var context = ContextFactory.CreateDbContext(); - - context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter - .SetProperty(t => t.BytesTransferred, args.Transfer.BytesTransferred) - .SetProperty(t => t.AverageSpeed, args.Transfer.AverageSpeed)); + // update only the properties that we expect to change between progress updates + // this helps prevent this update from 'stepping' on other updates + transfer.BytesTransferred = args.Transfer.BytesTransferred; + transfer.AverageSpeed = args.Transfer.AverageSpeed; + + // check again to see if the state changed while we were waiting to obtain the lock + if (transfer.State == TransferStates.InProgress) + { + using var context = ContextFactory.CreateDbContext(); + + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, args.Transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, args.Transfer.AverageSpeed)); + } + } + finally + { + syncRoot.Release(); } } - finally + else { - syncRoot.Release(); + Log.Debug("Skipped progress update of {Filename} to {Username} {BytesTransferred}/{TotalBytes}; previous update still pending", transfer.Filename, transfer.Username, args.Transfer.BytesTransferred, args.Transfer.Size); } } }), -- cgit v1.2.3 From 0fe0125a8a33a25f4452437693eb1008244d8f55 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 15:57:50 -0500 Subject: move SynchronizedUpdate --- src/slskd/Transfers/Uploads/UploadService.cs | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 037438cf..c4f123d4 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -223,20 +223,6 @@ namespace slskd.Transfers.Uploads var cts = new CancellationTokenSource(); var syncRoot = new SemaphoreSlim(1, 1); - void SynchronizedUpdate(Transfer transfer, bool cancellable = true) - { - syncRoot.Wait(cancellable ? cts.Token : CancellationToken.None); - - try - { - Update(transfer); - } - finally - { - syncRoot.Release(); - } - } - string host = default; string localFilename = default; long localFileLength = default; @@ -324,7 +310,7 @@ namespace slskd.Transfers.Uploads transfer = transfer.WithSoulseekTransfer(args.Transfer); // todo: broadcast - SynchronizedUpdate(transfer); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: cts.Token); }, progressUpdated: (args) => rateLimiter.Invoke(() => { @@ -379,7 +365,7 @@ namespace slskd.Transfers.Uploads // add the transfer to the UploadQueue so that it can become eligible for selection Queue.Enqueue(transfer.Username, transfer.Filename); transfer.EnqueuedAt = DateTime.UtcNow; - SynchronizedUpdate(transfer); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: cts.Token); Soulseek.Transfer completedTransfer; @@ -424,7 +410,7 @@ namespace slskd.Transfers.Uploads transfer = transfer.WithSoulseekTransfer(completedTransfer); // todo: broadcast - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); EventBus.Raise(new UploadFileCompleteEvent { @@ -442,7 +428,7 @@ namespace slskd.Transfers.Uploads transfer.Exception = "File could not be found"; transfer.State = TransferStates.Completed | TransferStates.Aborted; - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); throw; } @@ -460,7 +446,7 @@ namespace slskd.Transfers.Uploads }; // todo: broadcast - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); throw; } @@ -473,7 +459,7 @@ namespace slskd.Transfers.Uploads transfer.State = TransferStates.Completed | TransferStates.Errored; // todo: broadcast - SynchronizedUpdate(transfer, cancellable: false); + SynchronizedUpdate(transfer, semaphore: syncRoot, cancellationToken: CancellationToken.None); throw; } @@ -1005,5 +991,19 @@ namespace slskd.Transfers.Uploads return (host, filename, length); } + + private void SynchronizedUpdate(Transfer transfer, SemaphoreSlim semaphore, CancellationToken cancellationToken = default) + { + semaphore.Wait(cancellationToken); + + try + { + Update(transfer); + } + finally + { + semaphore.Release(); + } + } } } \ No newline at end of file -- cgit v1.2.3 From 8466136a29e9986dc8812b57a0691dad1e08e09e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 16:03:18 -0500 Subject: tweak for consistency with download --- src/slskd/Transfers/Uploads/UploadService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index c4f123d4..7cbc98d0 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -337,8 +337,8 @@ namespace slskd.Transfers.Uploads using var context = ContextFactory.CreateDbContext(); context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter - .SetProperty(t => t.BytesTransferred, args.Transfer.BytesTransferred) - .SetProperty(t => t.AverageSpeed, args.Transfer.AverageSpeed)); + .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); } } finally -- cgit v1.2.3 From 73d621141b9910645d4a1bc41b7bbbb05aedf1da Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 12 Oct 2025 16:09:15 -0500 Subject: remove deprecated double-check of state --- src/slskd/Transfers/Downloads/DownloadService.cs | 12 ++++-------- src/slskd/Transfers/Uploads/UploadService.cs | 14 +++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs index 4c70bca5..75a3c383 100644 --- a/src/slskd/Transfers/Downloads/DownloadService.cs +++ b/src/slskd/Transfers/Downloads/DownloadService.cs @@ -303,15 +303,11 @@ namespace slskd.Transfers.Downloads transfer.BytesTransferred = args.Transfer.BytesTransferred; transfer.AverageSpeed = args.Transfer.AverageSpeed; - // check again to see if the state changed while we were waiting to obtain the lock - if (transfer.State == TransferStates.InProgress) - { - using var context = ContextFactory.CreateDbContext(); + using var context = ContextFactory.CreateDbContext(); - context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter - .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) - .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); - } + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); } finally { diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index 7cbc98d0..4b35bffb 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -331,15 +331,11 @@ namespace slskd.Transfers.Uploads transfer.BytesTransferred = args.Transfer.BytesTransferred; transfer.AverageSpeed = args.Transfer.AverageSpeed; - // check again to see if the state changed while we were waiting to obtain the lock - if (transfer.State == TransferStates.InProgress) - { - using var context = ContextFactory.CreateDbContext(); - - context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter - .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) - .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); - } + using var context = ContextFactory.CreateDbContext(); + + context.Transfers.Where(t => t.Id == transfer.Id).ExecuteUpdate(setter => setter + .SetProperty(t => t.BytesTransferred, transfer.BytesTransferred) + .SetProperty(t => t.AverageSpeed, transfer.AverageSpeed)); } finally { -- cgit v1.2.3