fix: decouple background command execution from caller cancellation token (#7224) (#7283)

* 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:
Cristian Gintili 2026-04-09 11:44:33 +02:00 committed by GitHub
parent a0f0a3c2f5
commit 6bc0cf23ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)
{