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
16 changes: 16 additions & 0 deletions src/JasperFx.Events/Daemon/GroupedProjectionExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ private async Task<EventRange> groupEventRangeAsync(EventRange range, Cancellati

return range;
}
catch when (_cancellation.IsCancellationRequested)
{
// Shard is being torn down — don't promote the cancellation to a critical failure.
return null!;
}
catch (Exception e)
{
activity?.AddException(e);
Expand Down Expand Up @@ -183,6 +188,17 @@ private async Task processRangeAsync(EventRange range, CancellationToken _)

range.Agent.Metrics.UpdateProcessed(range.Size);
}
catch (OperationCanceledException) when (_cancellation.IsCancellationRequested)
{
// Daemon-internal cancellation (StopAllAsync / HardStopAsync / DisposeAsync fired the
// shard's CTS). Don't surface as a critical shard failure — matches the guard already
// used in applyBatchOperationsToDatabaseAsync and SubscriptionExecutionBase.executeRange.
}
catch when (_cancellation.IsCancellationRequested)
{
// Wrapped/aggregated cancellation (e.g. Npgsql 57014 surfaced through a non-OCE) that
// is really a side effect of the shard being torn down. Same rationale as above.
}
catch (Exception e)
{
activity?.AddException(e);
Expand Down
18 changes: 17 additions & 1 deletion src/JasperFx.Events/Daemon/JasperFxAsyncDaemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,11 @@ public async Task CatchUpAsync(CancellationToken cancellation)
var agent = buildAgentForShard(asyncShard);

await agent.CatchUpAsync(HighWaterMark(), state, cancellation);
var exceptions = recorder.States.Select(x => x.Exception).Where(x => x != null).ToArray();
var exceptions = recorder.States
.Select(x => x.Exception)
.Where(x => x != null)
.Where(x => cancellation.IsCancellationRequested || !isCancellationNoise(x!))
.ToArray();
if (exceptions.Length != 0)
{
throw new AggregateException(exceptions!);
Expand All @@ -724,6 +728,18 @@ public async Task CatchUpAsync(TimeSpan timeout, CancellationToken cancellation)
cts.CancelAfter(timeout);
await CatchUpAsync(cts.Token);
}

private static bool isCancellationNoise(Exception exception)
{
if (exception is OperationCanceledException) return true;
if (exception is AggregateException aggregate)
{
return aggregate.InnerExceptions.Count > 0
&& aggregate.InnerExceptions.All(isCancellationNoise);
}

return false;
}
}

internal class Recorder : IObserver<ShardState>
Expand Down
Loading