From 6bc0cf23ff75f123237a09d2979b3595b6810cee Mon Sep 17 00:00:00 2001 From: Cristian Gintili <48093965+cristiandolf@users.noreply.github.com> Date: Thu, 9 Apr 2026 11:44:33 +0200 Subject: [PATCH] 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> --- .../BackgroundCommandSenderHostedService.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/common/Elsa.Mediator/HostedServices/BackgroundCommandSenderHostedService.cs b/src/common/Elsa.Mediator/HostedServices/BackgroundCommandSenderHostedService.cs index 26916c831..d8aa66be5 100644 --- a/src/common/Elsa.Mediator/HostedServices/BackgroundCommandSenderHostedService.cs +++ b/src/common/Elsa.Mediator/HostedServices/BackgroundCommandSenderHostedService.cs @@ -78,17 +78,15 @@ public class BackgroundCommandSenderHostedService : BackgroundService using var scope = _scopeFactory.CreateScope(); var commandSender = scope.ServiceProvider.GetRequiredService(); - // 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) {