Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.NntpDb;
using VectorNNTPD.Common.Acme;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.Accounts
{
Expand Down Expand Up @@ -329,7 +330,7 @@ private async Task<bool> RefreshAsync(bool required, CancellationToken cancellat
{
throw;
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
if (required && !_hadSuccessfulSnapshot)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using VectorNNTPD.BackFillerService.Nntp;
using VectorNNTPD.BackFillerService.RabbitMq;
using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.Core;


namespace VectorNNTPD.BackFillerService.ArticleWork
Expand Down Expand Up @@ -240,7 +241,7 @@ public async Task StartAsync(CancellationToken cancellationToken)
await ReconcileSessionsAsync(cancellationToken).ConfigureAwait(false);
_reconcileLoop = RunReconcileLoopAsync(_reconcileCts.Token);
}
catch
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
_connections.ConnectionReplaced -= OnConnectionReplaced;
_capacity.SnapshotPublished -= OnCapacitySnapshotPublished;
Expand Down Expand Up @@ -431,7 +432,7 @@ private async Task ShutdownAsync(CancellationToken cancellationToken)
await replace.ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A background reconcile or replacement failure must be logged without faulting an unobserved task.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.ConsumerReplaceFailed(_logger, ex.Message);
}
Expand Down Expand Up @@ -498,7 +499,7 @@ private async Task RunReconcileLoopAsync(CancellationToken cancellationToken)
throw;
}
// codeql[cs/catch-of-all-exceptions] A reconcile fault must stay inside this loop so membership recovery continues.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
Interlocked.Increment(ref _unexpectedReconcileFaults);
ArticleWorkLogMessages.ConsumerReconcileFailed(_logger, ex.Message);
Expand Down Expand Up @@ -582,7 +583,7 @@ private async Task ReconcileObservedAsync()
await ReconcileAsync(CancellationToken.None).ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A background reconcile or replacement failure must be logged without faulting an unobserved task.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.ConsumerReplaceFailed(_logger, ex.Message);
}
Expand Down Expand Up @@ -687,7 +688,7 @@ private async Task<ReconcilePass> ReconcileSessionsAsync(CancellationToken cance
started.Add(session);
}
}
catch
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
foreach (var session in started)
{
Expand Down Expand Up @@ -1129,7 +1130,7 @@ private async Task FinishAcquiredReplacementAsync(
await ReconcileSessionsAsync(CancellationToken.None).ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A background reconcile or replacement failure must be logged without faulting an unobserved task.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.ConsumerReplaceFailed(_logger, ex.Message);
}
Expand Down Expand Up @@ -1158,7 +1159,7 @@ private async Task FinishQueuedReplacementAsync(Task replaceGateWait, Task start
await RunReplacementBodyAsync().ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A background reconcile or replacement failure must be logged without faulting an unobserved task.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.ConsumerReplaceFailed(_logger, ex.Message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using VectorNNTPD.BackFillerService.Logging;
using VectorNNTPD.BackFillerService.RabbitMq;
using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.ArticleWork
{
Expand Down Expand Up @@ -346,7 +347,7 @@ internal async Task StartAsync(CancellationToken cancellationToken)
"Channel closed during consumer start."));
}
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.ConsumerStartFailed(_logger, _backbone, _queue, ex.Message);
if (channel is not null)
Expand Down Expand Up @@ -582,7 +583,7 @@ await ArticleWorkSettlementLease.RunExclusiveAsync(
return true;
}
// codeql[cs/catch-of-all-exceptions] A session failure must be observed here so the consumer loop stays owned.
catch (Exception)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.ArticleWork
{
Expand Down Expand Up @@ -209,7 +210,7 @@ internal async Task<ArticleWorkOutcome> ProcessAsync(
error = null;
}
// codeql[cs/catch-of-all-exceptions] A delivery failure must be settled or logged by this pipeline boundary.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
outcome = ArticleWorkOutcome.UnexpectedFailure;
error = ex.GetType().Name;
Expand Down Expand Up @@ -414,7 +415,7 @@ await _publisher.PublishAsync(
return ArticleWorkPublishAttempt.Cancelled;
}
// codeql[cs/catch-of-all-exceptions] A delivery failure must be settled or logged by this pipeline boundary.
catch (Exception)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
return ArticleWorkPublishAttempt.Failed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public async Task StartAsync(CancellationToken cancellationToken)

ArticleWorkLogMessages.PublisherRunning(_logger, Generation);
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.PublisherStartFailed(_logger, ex.Message);
_connections.ConnectionReplaced -= OnConnectionReplaced;
Expand Down Expand Up @@ -229,7 +229,7 @@ public async ValueTask DisposeAsync()
await replace.ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A publish or replacement failure must not escape this publisher boundary.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.PublisherReplaceFailed(_logger, ex.Message);
}
Expand Down Expand Up @@ -536,7 +536,7 @@ private async Task RebuildPublishChannelAsync()
await ReplaceChannelAsync(startup: false, _runCts.Token).ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A publish or replacement failure must not escape this publisher boundary.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ArticleWorkLogMessages.PublisherReplaceFailed(_logger, ex.Message);
}
Expand Down Expand Up @@ -615,20 +615,16 @@ private async Task ReplaceChannelAsync(bool startup, CancellationToken cancellat
var channel = await handle.Connection
.CreatePublishChannelAsync(handle.Generation, cancellationToken)
.ConfigureAwait(false);
try
{
if (!handle.IsCurrent || channel.Generation != handle.Generation)
{
throw new InvalidOperationException("RabbitMQ publish channel generation is no longer current.");
}

await InstallPublishChannelAsync(channel).ConfigureAwait(false);
}
catch
await using var ownership = new AsyncDisposableOwnership<IRabbitMqPublishChannel>(channel);
if (!handle.IsCurrent || ownership.Resource.Generation != handle.Generation)
{
await channel.DisposeAsync().ConfigureAwait(false);
throw;
throw new InvalidOperationException("RabbitMQ publish channel generation is no longer current.");
}

// Install either stores the channel or disposes it as stale; Transfer after success
// so this ownership does not dispose again.
await InstallPublishChannelAsync(ownership.Resource).ConfigureAwait(false);
ownership.Transfer();
}

/// <summary>Clears and disposes the installed publication channel.</summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Runtime.CompilerServices;
using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.ArticleWork
{
Expand Down Expand Up @@ -110,7 +111,7 @@ await _channel.BasicRejectAsync(_deliveryTag, disposition.Requeue, CancellationT
return true;
}
// codeql[cs/catch-of-all-exceptions] Settlement cleanup must finish even when an unexpected exception is thrown.
catch (Exception)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Text;
using VectorNNTPD.Common.Configuration;
using NntpArticleIdentity = VectorNNTPD.Common.Articles.Processing.NntpArticleIdentity;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.ArticleWork
{
Expand Down Expand Up @@ -323,7 +324,7 @@ public async ValueTask<ArticleWorkHandlerResult> HandleAsync(
cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
LogArticleProcessed(item, OutcomeFailed, string.Empty, CommandTimestamp(ex));
if (ex is OperationCanceledException && cancellationToken.IsCancellationRequested)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using VectorNNTPD.BackFillerService.Networking;
using VectorNNTPD.Common.Messaging.RabbitMq;
using VectorNNTPD.Common.Configuration;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.Configuration
{
Expand Down Expand Up @@ -416,7 +417,7 @@ private void ValidateArticleRetention(BackFillerOptions options, List<string> fa
totalPhysicalMemoryBytes = _physicalMemoryProvider.GetTotalPhysicalMemoryBytes();
}
// codeql[cs/catch-of-all-exceptions] Validation must report every rejected value and continue checking the remaining options.
catch (Exception)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
failures.Add(
$"The host must have at least {BackFillerArticleRetentionOptions.MinimumPhysicalMemoryGibibytes} GiB ({BackFillerArticleRetentionOptions.MinimumPhysicalMemoryBytes} bytes) of physical RAM, but total physical memory could not be determined.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ internal async Task StopAsync(CancellationToken cancellationToken)
ApplicationServiceManagerLogMessages.ServiceStopAbortedAfterBudget(_logger, service.Name);
}
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ApplicationServiceManagerLogMessages.ServiceStopFailed(_logger, ex, service.Name);
failures.Add(ex);
Expand Down Expand Up @@ -383,7 +383,7 @@ private async Task RollbackStartedAsync(CancellationToken cancellationToken)
await service.StopAsync(timeoutCts.Token).ConfigureAwait(false);
}
// codeql[cs/catch-of-all-exceptions] A service start or stop failure must be recorded without abandoning the remaining services.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
ApplicationServiceManagerLogMessages.ServiceRollbackFailed(_logger, ex, service.Name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Extensions.Hosting.Systemd;
using Serilog.Debugging;
using VectorNNTPD.BackFillerService.Logging;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.Hosting.Systemd
{
Expand Down Expand Up @@ -113,21 +114,21 @@ private void Notify(ServiceState state, string label)
SystemdLogMessages.NotificationSent(_logger, label);
}
// codeql[cs/catch-of-all-exceptions] A notification or diagnostic failure must not escape the notifier.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
try
{
SystemdLogMessages.NotificationFailed(_logger, ex, label);
}
// codeql[cs/catch-of-all-exceptions] A notification or diagnostic failure must not escape the notifier.
catch (Exception logFailure)
catch (Exception logFailure) when (!ExceptionHelpers.IsFatal(logFailure))
{
try
{
SelfLog.WriteLine("systemd notification failure log failed: {0}", logFailure);
}
// codeql[cs/catch-of-all-exceptions] A notification or diagnostic failure must not escape the notifier.
catch (Exception)
catch (Exception selfLogFailure) when (!ExceptionHelpers.IsFatal(selfLogFailure))
{
// Notification and its diagnostic log are both best-effort.
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using VectorNNTPD.BackFillerService.Configuration;
using VectorNNTPD.BackFillerService.Logging;
using Microsoft.Extensions.Options;
using VectorNNTPD.Common.Core;

namespace VectorNNTPD.BackFillerService.Hosting.Systemd
{
Expand Down Expand Up @@ -171,7 +172,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
SystemdLogMessages.WatchdogKeepAliveSent(_logger);
}
// codeql[cs/catch-of-all-exceptions] A watchdog notify failure must be logged and must not stop the process.
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
// Unlike NNTPD, notify failures must not stop BackFiller. Missing
// keep-alives still trip systemd when WatchdogSec is configured.
Expand All @@ -183,7 +184,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
SystemdLogMessages.WatchdogDeactivated(_logger);
}
catch (Exception ex)
catch (Exception ex) when (!ExceptionHelpers.IsFatal(ex))
{
SystemdLogMessages.WatchdogLoopFailed(_logger, ex);
Interlocked.Exchange(ref _active, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

using System.Net;
using System.Net.Sockets;
using VectorNNTPD.Common.Core;
using VectorNNTPD.Common.Networking.Listeners;

namespace VectorNNTPD.BackFillerService.Listener
Expand Down Expand Up @@ -36,24 +36,18 @@ internal static Socket CreateBoundListenSocket(ListenBinding binding)
private static Socket CreateBoundListenSocket(IPEndPoint endpoint, bool dualMode = false)
{
ArgumentNullException.ThrowIfNull(endpoint);
var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
using var ownership = new DisposableOwnership<Socket>(
new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp));
var socket = ownership.Resource;

if (endpoint.AddressFamily == AddressFamily.InterNetworkV6)
{
socket.DualMode = dualMode;
}

try
{
socket.Bind(endpoint);
socket.Listen(512);
return socket;
}
catch
{
socket.Dispose();
throw;
}
socket.Bind(endpoint);
socket.Listen(512);
return ownership.Transfer();
}
}
}
Loading
Loading