Skip to content

Commit

Permalink
Ensure TrySetException is always set on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonsmits committed Feb 7, 2025
1 parent 5a5533e commit 8b942ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/ServiceControl.Audit/Auditing/AuditIngestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,20 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await auditIngestor.Ingest(contexts);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
catch (Exception e)
{
throw; // Catch again in outer catch
}
catch (Exception e) // show must go on
{
logger.Info("Ingesting messages failed", e);

// signal all message handling tasks to terminate
foreach (var context in contexts)
{
context.GetTaskCompletionSource().TrySetException(e);
_ = context.GetTaskCompletionSource().TrySetException(e);
}

if (e is OperationCanceledException && stoppingToken.IsCancellationRequested)
{
break; // ExecuteAsync cancelled
}

logger.Info("Ingesting messages failed", e);
}
finally
{
Expand Down
17 changes: 9 additions & 8 deletions src/ServiceControl/Operations/ErrorIngestion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,20 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await ingestor.Ingest(contexts);
}
}
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
catch (Exception e)
{
throw; // Catch again in outer catch
}
catch (Exception e) // show must go on
{
Logger.Info("Ingesting messages failed", e);

// signal all message handling tasks to terminate
foreach (var context in contexts)
{
context.GetTaskCompletionSource().TrySetException(e);
_ = context.GetTaskCompletionSource().TrySetException(e);
}

if (e is OperationCanceledException && stoppingToken.IsCancellationRequested)
{
break; // ExecuteAsync cancelled
}

Logger.Info("Ingesting messages failed", e);
}
finally
{
Expand Down

0 comments on commit 8b942ff

Please sign in to comment.