Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

fix: fail queue items with missing nzb blobs instead of blocking queue (#351)

David Younga146d07d8c62
diff --git a/backend/Queue/QueueItemProcessor.cs b/backend/Queue/QueueItemProcessor.cs
index 6eb4f1c1..6fd901f7 100644
--- a/backend/Queue/QueueItemProcessor.cs
+++ b/backend/Queue/QueueItemProcessor.cs
@@ -23,7 +23,7 @@ namespace NzbWebDAV.Queue;
public class QueueItemProcessor(
QueueItem queueItem,
- Stream queueNzbStream,
+ Stream? queueNzbStream,
DavDatabaseClient dbClient,
INntpClient usenetClient,
ConfigManager configManager,
@@ -92,6 +92,12 @@ public class QueueItemProcessor(
private async Task ProcessQueueItemAsync(DateTime startTime)
{
+ // if the `/blobs` folder is tampered with outside the nzbdav process,
+ // then it is possible that the nzb file goes missing.
+ if (queueNzbStream is null)
+ throw new Exception($"The NZB file could not be found.");
+
+ // load config for handling duplicate nzbs
var existingMountFolder = await GetMountFolder().ConfigureAwait(false);
var duplicateNzbBehavior = configManager.GetDuplicateNzbBehavior();
@@ -385,4 +391,4 @@ public class QueueItemProcessor(
Log.Debug($"Could not refresh monitored downloads for Arr instance: `{arrClient.Host}`. {e.Message}");
}
}
-}
\ No newline at end of file
+}
diff --git a/backend/Queue/QueueManager.cs b/backend/Queue/QueueManager.cs
index 89fc031f..cf8b706c 100644
--- a/backend/Queue/QueueManager.cs
+++ b/backend/Queue/QueueManager.cs
@@ -1,4 +1,4 @@
-using NzbWebDAV.Clients.Usenet;
+using NzbWebDAV.Clients.Usenet;
using NzbWebDAV.Config;
using NzbWebDAV.Database;
using NzbWebDAV.Database.Models;
@@ -85,7 +85,7 @@ public class QueueManager : IDisposable
await using var dbContext = new DavDatabaseContext();
var dbClient = new DavDatabaseClient(dbContext);
var topItem = await LockAsync(() => dbClient.GetTopQueueItem(ct)).ConfigureAwait(false);
- if (topItem.queueItem is null || topItem.queueNzbStream is null)
+ if (topItem.queueItem is null)
{
try
{
@@ -113,15 +113,22 @@ public class QueueManager : IDisposable
using var cachingUsenetClient = new ArticleCachingNntpClient(_usenetClient);
// process the queue-item
- await using var queueNzbStream = topItem.queueNzbStream;
- using var queueItemCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(ct);
- await LockAsync(() =>
+ try
{
- // ReSharper disable twice AccessToDisposedClosure
- _inProgressQueueItem = BeginProcessingQueueItem(dbClient, cachingUsenetClient,
- topItem.queueItem, queueNzbStream, queueItemCancellationTokenSource);
- }).ConfigureAwait(false);
- await (_inProgressQueueItem?.ProcessingTask ?? Task.CompletedTask).ConfigureAwait(false);
+ using var queueItemCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(ct);
+ await LockAsync(() =>
+ {
+ // ReSharper disable twice AccessToDisposedClosure
+ _inProgressQueueItem = BeginProcessingQueueItem(dbClient, cachingUsenetClient,
+ topItem.queueItem, topItem.queueNzbStream, queueItemCancellationTokenSource);
+ }).ConfigureAwait(false);
+ await (_inProgressQueueItem?.ProcessingTask ?? Task.CompletedTask).ConfigureAwait(false);
+ }
+ finally
+ {
+ if (topItem.queueItem is not null)
+ await topItem.queueNzbStream!.DisposeAsync();
+ }
}
catch (Exception e)
{
@@ -139,7 +146,7 @@ public class QueueManager : IDisposable
DavDatabaseClient dbClient,
INntpClient usenetClient,
QueueItem queueItem,
- Stream queueNzbStream,
+ Stream? queueNzbStream,
CancellationTokenSource cts
)
{
@@ -218,4 +225,4 @@ public class QueueManager : IDisposable
public Task ProcessingTask { get; init; }
public CancellationTokenSource CancellationTokenSource { get; init; }
}
-}
\ No newline at end of file
+}