Skip to content

Commit bf99b69

Browse files
committed
OnMessage: Invoke TrySetCanceled when cancelled to return ASAP
1 parent bd1bc9f commit bf99b69

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ServiceControl/Operations/ErrorIngestion.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ async Task OnMessage(MessageContext messageContext, CancellationToken cancellati
269269
}
270270

271271
var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
272-
messageContext.SetTaskCompletionSource(taskCompletionSource);
272+
273+
// Ideally we want to propagate the cancellationToken to the batch handling
274+
// but cancellation in only cancelled when endpointInstance.Stop is cancelled, not when invoked.
275+
// Not much shutdown speed to gain but this will ensure endpoint.Stop will return.
276+
await using var cancellationTokenRegistration = cancellationToken.Register(() => _ = taskCompletionSource.TrySetCanceled());
273277

274278
receivedMeter.Mark();
275279

0 commit comments

Comments
 (0)