Skip to content

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

C#

Do not log TaskCanceledException on sigterm signal.

nzbdav-devb5c8a7dded23
diff --git a/backend/Services/BlobCleanupService.cs b/backend/Services/BlobCleanupService.cs
index dc664830..e6351663 100644
--- a/backend/Services/BlobCleanupService.cs
+++ b/backend/Services/BlobCleanupService.cs
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using NzbWebDAV.Database;
+using NzbWebDAV.Utils;
using Serilog;
namespace NzbWebDAV.Services;
@@ -40,6 +41,11 @@ public class BlobCleanupService : BackgroundService
// Continue immediately to next iteration to process more items
}
+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())
+ {
+ // OperationCanceledException is expected on sigterm
+ return;
+ }
catch (Exception e)
{
Log.Error(e, $"Error processing blob cleanup queue: {e.Message}");
diff --git a/backend/Services/DavCleanupService.cs b/backend/Services/DavCleanupService.cs
index 249f1b72..deab89b3 100644
--- a/backend/Services/DavCleanupService.cs
+++ b/backend/Services/DavCleanupService.cs
@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using NzbWebDAV.Database;
using NzbWebDAV.Database.Models;
+using NzbWebDAV.Utils;
using Serilog;
namespace NzbWebDAV.Services;
@@ -48,6 +49,11 @@ public class DavCleanupService : BackgroundService
// Continue immediately to next iteration to process more items
}
+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())
+ {
+ // OperationCanceledException is expected on sigterm
+ return;
+ }
catch (Exception e)
{
Log.Error(e, $"Error processing dav cleanup queue: {e.Message}");
diff --git a/backend/Services/HealthCheckService.cs b/backend/Services/HealthCheckService.cs
index a2baeb2b..d7528402 100644
--- a/backend/Services/HealthCheckService.cs
+++ b/backend/Services/HealthCheckService.cs
@@ -78,6 +78,11 @@ public class HealthCheckService : BackgroundService
// perform the health check
await PerformHealthCheck(davItem, dbClient, concurrency, cts.Token).ConfigureAwait(false);
}
+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())
+ {
+ // OperationCanceledException is expected on sigterm
+ return;
+ }
catch (Exception e)
{
Log.Error(e, $"Unexpected error performing background health checks: {e.Message}");
diff --git a/backend/Services/HistoryCleanupService.cs b/backend/Services/HistoryCleanupService.cs
index 5ea1a4de..8b7ebe8c 100644
--- a/backend/Services/HistoryCleanupService.cs
+++ b/backend/Services/HistoryCleanupService.cs
@@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using NzbWebDAV.Database;
using NzbWebDAV.Database.Models;
+using NzbWebDAV.Utils;
using Serilog;
namespace NzbWebDAV.Services;
@@ -61,6 +62,11 @@ public class HistoryCleanupService : BackgroundService
// Continue immediately to next iteration to process more items
}
+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())
+ {
+ // OperationCanceledException is expected on sigterm
+ return;
+ }
catch (Exception e)
{
Log.Error(e, $"Error processing history cleanup queue: {e.Message}");
diff --git a/backend/Services/NzbBlobCleanupService.cs b/backend/Services/NzbBlobCleanupService.cs
index 91ab4bb7..c6fcad9d 100644
--- a/backend/Services/NzbBlobCleanupService.cs
+++ b/backend/Services/NzbBlobCleanupService.cs
@@ -2,6 +2,7 @@ using System.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Hosting;
using NzbWebDAV.Database;
+using NzbWebDAV.Utils;
using Serilog;
namespace NzbWebDAV.Services;
@@ -81,6 +82,11 @@ public class NzbBlobCleanupService : BackgroundService
// Continue immediately to next iteration to process more items
}
+ catch (OperationCanceledException) when (SigtermUtil.IsSigtermTriggered())
+ {
+ // OperationCanceledException is expected on sigterm
+ return;
+ }
catch (Exception e)
{
Log.Error(e, $"Error processing NZB blob cleanup queue: {e.Message}");
diff --git a/backend/Utils/SigtermUtil.cs b/backend/Utils/SigtermUtil.cs
index 4c6ee94b..68134f2f 100644
--- a/backend/Utils/SigtermUtil.cs
+++ b/backend/Utils/SigtermUtil.cs
@@ -40,6 +40,11 @@ public static class SigtermUtil
return CancellationTokenSource.Token;
}
+ public static bool IsSigtermTriggered()
+ {
+ return GetCancellationToken().IsCancellationRequested;
+ }
+
public static void Cancel()
{
CancellationTokenSource.Cancel();