Skip to content

Commit 8b942ff

Browse files
committed
Ensure TrySetException is always set on exception
1 parent 5a5533e commit 8b942ff

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/ServiceControl.Audit/Auditing/AuditIngestion.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,20 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
223223
await auditIngestor.Ingest(contexts);
224224
}
225225
}
226-
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
226+
catch (Exception e)
227227
{
228-
throw; // Catch again in outer catch
229-
}
230-
catch (Exception e) // show must go on
231-
{
232-
logger.Info("Ingesting messages failed", e);
233-
234228
// signal all message handling tasks to terminate
235229
foreach (var context in contexts)
236230
{
237-
context.GetTaskCompletionSource().TrySetException(e);
231+
_ = context.GetTaskCompletionSource().TrySetException(e);
238232
}
233+
234+
if (e is OperationCanceledException && stoppingToken.IsCancellationRequested)
235+
{
236+
break; // ExecuteAsync cancelled
237+
}
238+
239+
logger.Info("Ingesting messages failed", e);
239240
}
240241
finally
241242
{

src/ServiceControl/Operations/ErrorIngestion.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,20 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
9999
await ingestor.Ingest(contexts);
100100
}
101101
}
102-
catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
102+
catch (Exception e)
103103
{
104-
throw; // Catch again in outer catch
105-
}
106-
catch (Exception e) // show must go on
107-
{
108-
Logger.Info("Ingesting messages failed", e);
109-
110104
// signal all message handling tasks to terminate
111105
foreach (var context in contexts)
112106
{
113-
context.GetTaskCompletionSource().TrySetException(e);
107+
_ = context.GetTaskCompletionSource().TrySetException(e);
114108
}
109+
110+
if (e is OperationCanceledException && stoppingToken.IsCancellationRequested)
111+
{
112+
break; // ExecuteAsync cancelled
113+
}
114+
115+
Logger.Info("Ingesting messages failed", e);
115116
}
116117
finally
117118
{

0 commit comments

Comments
 (0)