elsa-workflows / elsa-core

A .NET workflows library
https://v3.elsaworkflows.io/
MIT License
6.57k stars 1.21k forks source link

[BUG] Delay node doesn't work when TimeSpan Input has the value of 72:00:00 #5978

Open cristianDrDr opened 2 months ago

cristianDrDr commented 2 months ago

Description

Specifying the input value of 72:00:00 in the delay node creates a bookmark that has the resume at in 72 days in the elsa.bookmarks table but not on the instance. The impact is that the background service fails to process it and it crashes. Anything above 25 days seems to fail.

Steps to Reproduce

Add a delay node and add the value of 72:00:00 in the TimeSpan input. Run the workflow Restart the background service The background service fails to start back up with the error of Invalid value '6220688071.5474' for parameter 'interval'.

  1. Reproduction Rate: every time

Expected Behavior

The background service processes the instance as per configuration

Actual Behavior

The background service crashes

Log Output

fail: Microsoft.Extensions.Hosting.Internal.Host[9] BackgroundService failed System.ArgumentException: Invalid value '6220688071.5474' for parameter 'interval'. at System.Timers.Timer..ctor(Double interval) at Elsa.Scheduling.ScheduledTasks.ScheduledSpecificInstantTask.Schedule() at Elsa.Scheduling.ScheduledTasks.ScheduledSpecificInstantTask..ctor(ITask task, DateTimeOffset startAt, ISystemClock systemClock, IServiceScopeFactory scopeFactory) at InvokeStub_ScheduledSpecificInstantTask..ctor(Object, Span1) at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance[T](IServiceProvider provider, Object[] parameters) at Elsa.Scheduling.Schedules.SpecificInstantSchedule.Schedule(ScheduleContext context) at Elsa.Scheduling.Services.LocalScheduler.ScheduleAsync(String name, ITask task, ISchedule schedule, IEnumerable1 keys, CancellationToken cancellationToken) at Elsa.Scheduling.Services.LocalScheduler.ScheduleAsync(String name, ITask task, ISchedule schedule, CancellationToken cancellationToken) at Elsa.Scheduling.Services.DefaultWorkflowScheduler.ScheduleAtAsync(String taskName, DispatchWorkflowInstanceRequest request, DateTimeOffset at, CancellationToken cancellationToken) at Elsa.Scheduling.Services.DefaultBookmarkScheduler.ScheduleAsync(IEnumerable1 bookmarks, CancellationToken cancellationToken)`

Troubleshooting Attempts

Setting the format of the TimeSpan to 72.00:00:00 yields the same result but smaller values like 3.00:00:00 seem to work.

Sverre-W commented 2 months ago

Hi Cristian,

Have you considered using Hangfire or Quartz as the scheduling backend for your activities? It looks like the issue stems from the default Elsa scheduler, which uses System.Timers.Timer to handle delays. The Timer class accepts intervals as an int, with a maximum value of 2,147,483,647. This translates to just under 25 days, which is causing the error you're encountering.