aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs20
-rw-r--r--src/slskd/Transfers/Uploads/UploadService.cs19
2 files changed, 20 insertions, 19 deletions
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index eafbf388..be9278b2 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -203,16 +203,6 @@ namespace slskd.Transfers.Downloads
/// <exception cref="DuplicateTransferException">Thrown if a download matching the username and filename is already tracked by Soulseek.NET.</exception>
public async Task<Transfer> DownloadAsync(Transfer transfer)
{
- var lockName = $"{nameof(DownloadAsync)}:{transfer.Username}:{transfer.Filename}";
-
- if (!Locks.TryAdd(lockName, true))
- {
- Log.Debug("Ignoring concurrent invocation; lock {LockName} already held", lockName);
- return null;
- }
-
- Log.Debug("Acquired lock {LockName}", lockName);
-
var cts = new CancellationTokenSource();
var syncRoot = new SemaphoreSlim(1, 1);
@@ -230,6 +220,14 @@ namespace slskd.Transfers.Downloads
}
}
+ var lockName = $"{nameof(DownloadAsync)}:{transfer.Username}:{transfer.Filename}";
+
+ if (!Locks.TryAdd(lockName, true))
+ {
+ Log.Debug("Ignoring concurrent invocation; lock {LockName} already held", lockName);
+ return null;
+ }
+
/*
from this point forward, any exit from this method MUST result in an update to the Transfer record
in the database that sets EndedAt and ensures that the State property includes the Completed flag
@@ -240,6 +238,8 @@ namespace slskd.Transfers.Downloads
*/
try
{
+ Log.Debug("Acquired lock {LockName}", lockName);
+
/*
fetch an updated copy of the transfer record from the database; now that we are locked, we *should*
have exclusive access to this record
diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs
index bd167a57..89700eba 100644
--- a/src/slskd/Transfers/Uploads/UploadService.cs
+++ b/src/slskd/Transfers/Uploads/UploadService.cs
@@ -220,15 +220,6 @@ namespace slskd.Transfers.Uploads
/// <exception cref="NotFoundException">Thrown if the specified file can't be found on disk.</exception>
public async Task<Transfer> UploadAsync(Transfer transfer)
{
- var lockName = $"{nameof(UploadAsync)}:{transfer.Username}:{transfer.Filename}";
-
- if (!Locks.TryAdd(lockName, true))
- {
- Log.Debug("Ignoring concurrent invocation; lock {LockName} already held", lockName);
- return null;
- }
-
- Log.Debug("Acquired lock {LockName}", lockName);
var cts = new CancellationTokenSource();
var syncRoot = new SemaphoreSlim(1, 1);
@@ -251,6 +242,14 @@ namespace slskd.Transfers.Uploads
string localFilename = default;
long localFileLength = default;
+ var lockName = $"{nameof(UploadAsync)}:{transfer.Username}:{transfer.Filename}";
+
+ if (!Locks.TryAdd(lockName, true))
+ {
+ Log.Debug("Ignoring concurrent invocation; lock {LockName} already held", lockName);
+ return null;
+ }
+
/*
from this point forward, any exit from this method MUST result in an update to the Transfer record
in the database that sets EndedAt and ensures that the State property includes the Completed flag
@@ -261,6 +260,8 @@ namespace slskd.Transfers.Uploads
*/
try
{
+ Log.Debug("Acquired lock {LockName}", lockName);
+
/*
fetch an updated copy of the transfer record from the database; now that we are locked, we *should*
have exclusive access to this record