elsa-core
elsa-core copied to clipboard
[BUG] Duplicate executions when using the default scheduling provider in single-node environment
Description
Configuring the scheduling activities with the default provider (neither quartz nor hangfire), in a single-node environment has a few issues like duplicate executions when updating an existing workflow and errors thrown when unpolishing a workflow.
Steps to Reproduce
Scenario 1: Unpublishing and publishing again will cause duplicate executions. Basically the first triggers will not be removed.
Scenario 2: Changing the value of the cron will have the same effect as scenario 2.
Scenario 3: Unpublishing a workflow will stop the timer but it is done by accident. The application will keep trying to execute the workflow but since it is unpublished it will throw this error:
fail: Elsa.Mediator.HostedServices.BackgroundCommandSenderHostedService[0]
An unhandled exception occured while processing the queue
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.AggregateException: One or more errors occurred. (Specified workflow definition and version does not exist)
---> System.Exception: Specified workflow definition and version does not exist
at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.CreateWorkflowHostAsync(String definitionId, StartWorkflowRuntimeParams options, CancellationToken cancellationToken)
at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.StartWorkflowAsync(String definitionId, StartWorkflowRuntimeParams options)
at Elsa.Workflows.Runtime.Services.DefaultWorkflowRuntime.TryStartWorkflowAsync(String definitionId, StartWorkflowRuntimeParams options)
at Elsa.Workflows.Runtime.Handlers.DispatchWorkflowCommandHandler.HandleAsync(DispatchWorkflowDefinitionCommand command, CancellationToken cancellationToken)
at Elsa.Mediator.CommandStrategies.DefaultStrategy.ExecuteAsync[TResult](CommandStrategyContext context)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at InvokeStub_Task`1.get_Result(Object, Object, IntPtr*)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
at System.Reflection.PropertyInfo.GetValue(Object obj)
at Elsa.Mediator.Middleware.Command.Components.CommandHandlerInvokerMiddleware.InvokeAsync(CommandContext context)
at Elsa.Mediator.Middleware.Command.CommandPipeline.InvokeAsync(CommandContext context)
at Elsa.Mediator.Services.DefaultMediator.SendAsync(ICommand command, ICommandStrategy strategy, CancellationToken cancellationToken)
at Elsa.Mediator.HostedServices.BackgroundCommandSenderHostedService.ReadOutputAsync(Channel`1 output, CancellationToken cancellationToken)
The issues can be reproduced every time.
The startup configuration:
.UseScheduling()
Cron expressions used:
- */20 * * * * *
- */10 * * * * *
Expected Behavior
The expected behaviors are:
- When you republish a workflow, you won't get duplicate executions. The previous triggers are removed.
- When updating the cron value, the old triggers should be removed/be overridden by the new ones.
- When you unpublish a cron workflow, instances are not being created anymore and no errors are thrown.
Workaround
Using the quartz provider is working as expected, without the issues mentioned.
Environment
- Elsa version used: 3.2.0-preview.1616
- Mass transit was disabled.
- Default runtime