* fix: decouple background command execution from caller cancellation token (fixes #7224) * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
a0f0a3c2f5
commit
6bc0cf23ff
|
|
@ -78,17 +78,15 @@ public class BackgroundCommandSenderHostedService : BackgroundService
|
|||
using var scope = _scopeFactory.CreateScope();
|
||||
var commandSender = scope.ServiceProvider.GetRequiredService<ICommandSender>();
|
||||
|
||||
// Link the service cancellation token with the command's token to ensure proper cancellation
|
||||
using var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
|
||||
cancellationToken,
|
||||
commandContext.CancellationToken);
|
||||
|
||||
// Process the command using the command sender service with the linked token
|
||||
// Decouple from the caller's CancellationToken.
|
||||
// We use only the service's cancellationToken (the background worker's lifetime)
|
||||
// to ensure that dispatched workflows are processed even if the original
|
||||
// HTTP request or triggering context has timed out.
|
||||
await commandSender.SendAsync(
|
||||
commandContext.Command,
|
||||
CommandStrategy.Default,
|
||||
commandContext.Headers,
|
||||
linkedTokenSource.Token);
|
||||
cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue