Azure / durabletask

Durable Task Framework allows users to write long running persistent workflows in C# using the async/await capabilities.
Apache License 2.0
1.47k stars 287 forks source link

unexpected event type of type 'OrchestratorStarted' #1095

Closed DDAndyChen closed 1 month ago

DDAndyChen commented 1 month ago

Getting some errors in the log stream when testing the Counter example, in fact, all of my durable entities is not running for this same error. what might be the issue?

2024-05-19T12:41:21Z   [Error]   TaskEntityDispatcher-23269d6ab59b427f8acb4adf3ecd0dac-0: Unhandled exception with work item '@counter@myCounter': DurableTask.Core.Exceptions.EntitySchedulerException: The entity with instanceId '@counter@myCounter' received an unexpected event type of type 'OrchestratorStarted'. This is not a valid entity message. This is a framework-internal error, please report this issue in the GitHub repo: 'https://github.com/Azure/durabletask/'
   at DurableTask.Core.TaskEntityDispatcher.DetermineWork(OrchestrationRuntimeState runtimeState, SchedulerState& schedulerState, Work& batch) in /_/src/DurableTask.Core/TaskEntityDispatcher.cs:line 568
   at DurableTask.Core.TaskEntityDispatcher.OnProcessWorkItemAsync(TaskOrchestrationWorkItem workItem) in /_/src/DurableTask.Core/TaskEntityDispatcher.cs:line 241
   at DurableTask.Core.TaskEntityDispatcher.OnProcessWorkItemAsync(TaskOrchestrationWorkItem workItem) in /_/src/DurableTask.Core/TaskEntityDispatcher.cs:line 377
   at DurableTask.Core.TaskEntityDispatcher.OnProcessWorkItemSessionAsync(TaskOrchestrationWorkItem workItem) in /_/src/DurableTask.Core/TaskEntityDispatcher.cs:line 122
   at DurableTask.Core.WorkItemDispatcher`1.ProcessWorkItemAsync(WorkItemDispatcherContext context, Object workItemObj) in /_/src/DurableTask.Core/WorkItemDispatcher.cs:line 373

Here is my code

internal class Tests
{
    [Function("AddFromQueue")]
    public static Task Run(
        [HttpTrigger(AuthorizationLevel.Admin, "post", Route = "api/tests/test")]
        HttpRequest req,
        [DurableClient] DurableTaskClient client)
    {
        // Entity operation input comes from the queue message content.
        var entityId = new EntityInstanceId(nameof(Counter), "myCounter");
        int amount = 32;
        return client.Entities.SignalEntityAsync(entityId, "Add", amount);
    }
}

public class Counter : TaskEntity<int>
{
    private readonly ILogger logger;

    public Counter(ILogger<Counter> logger)
    {
        this.logger = logger;
    }

    public void Add(int amount) => this.State += amount;

    public void Reset() => this.State = 0;

    public int Get() => this.State;

    [Function(nameof(Counter))]
    public static Task RunEntityStaticAsync([EntityTrigger] TaskEntityDispatcher dispatcher)
    {
        return dispatcher.DispatchAsync<Counter>();
    }
}
thomaseyde commented 1 month ago

The issue is a bug in Microsoft.Azure.Functions.Worker.Extensions.DurableTask version 1.1.3. Downgrade to version 1.1.2 and it will work.

This is getting boring. I want to be productive with Durable Task, not be a beta tester. I have long lived without the ability to signal between entities, now this happens.

kweebtronic commented 1 month ago

Introduced by this PR , MS trying to fix this P1 issue

nytian commented 1 month ago

Hey @DDAndyChen I am sorry for the inconvenience and trouble caused by this. The issue is caused by an inappropriate error handling. To mitigate the issue immediately, we have a pre-released ADO feed to use, (Official release might take some time, but we will put this on agenda asap). If you are willing to try, the ADO feed is here. To use this feed, you need to first connect with feed, detailed instructions can be found here : you need to first add package source durabletask-test, and then run command dotnet restore. After successfully connected, you can use the feed directly in your project. Please let me know if you have any question regarding this. Thank you!

nytian commented 1 month ago

Hi, @DDAndyChen The package with the hotfixes has been released. Please use the package v1.1.4 instead to mitigate the issue. nuget link: https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.DurableTask/1.1.4 And please let me know if there is any problem. Sorry for the trouble!

DDAndyChen commented 1 month ago

@nytian The new package works for me now! Thank you.