mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
fix: prevent duplicate downloads and lock release bug
- Track lock state to prevent double-release in finally block - Fixes exception when download is already in progress - Prevents duplicate file downloads with (1), (2), (3) suffixes - Ensures proper lock management during concurrent download requests
This commit is contained in:
@@ -264,6 +264,7 @@ public abstract class BaseDownloadService : IDownloadService
|
||||
|
||||
// Acquire lock BEFORE checking existence to prevent race conditions with concurrent requests
|
||||
await DownloadLock.WaitAsync(cancellationToken);
|
||||
var lockHeld = true;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -288,6 +289,7 @@ public abstract class BaseDownloadService : IDownloadService
|
||||
Logger.LogDebug("Download already in progress for {SongId}, waiting for completion...", songId);
|
||||
// Release lock while waiting
|
||||
DownloadLock.Release();
|
||||
lockHeld = false;
|
||||
|
||||
// Wait for download to complete, checking every 100ms (faster than 500ms)
|
||||
// Also respect cancellation token so client timeouts are handled immediately
|
||||
@@ -444,7 +446,10 @@ public abstract class BaseDownloadService : IDownloadService
|
||||
}
|
||||
finally
|
||||
{
|
||||
DownloadLock.Release();
|
||||
if (lockHeld)
|
||||
{
|
||||
DownloadLock.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user