0
votes

I'm attempting to follow the code as an example laid out here, https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-eternal-orchestrations?irgwc=1&OCID=AID2000142_aff_7593_1375745&tduid=(ir__6jtlnbrfc0kft3svkk0sohznxn2xi0sgvpzqs0fg00)(7593)(1375745)()()&irclickid=_6jtlnbrfc0kft3svkk0sohznxn2xi0sgvpzqs0fg00&tabs=csharp, for creating an Eternal Orchestration in Durable Functions.

Currently, I have an HTTP triggered function

[FunctionName("Trigger_Eternal_Orchestration")]
public static async Task<HttpResponseMessage> OrchestrationTrigger(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage request,
    [DurableClient] IDurableOrchestrationClient client)
{
    string id = request.Query["Id"];

    await client.StartNewAsync("Periodic_Cleanup_Loop", instanceId).ConfigureAwait(false); 
    return client.CreateCheckStatusResponse(request, instanceId);
}

and the orchestration trigger function as

[FunctionName("Periodic_Cleanup_Loop")]
public static async Task Run(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    DateTime nextCleanup = context.CurrentUtcDateTime.AddSeconds(10);
    await context.CreateTimer(nextCleanup, CancellationToken.None);
    Console.WriteLine("Going again");
    context.ContinueAsNew(null);
}

Right now I'm just trying to see the eternal orchestration work (see the print out every 10 seconds) but after only one execution I always get the error:

Multithreaded execution was detected. This can happen if the orchestrator function code awaits on a task that was not created by a DurableOrchestrationContext method.

I'm not sure what the error is exactly based on the message given that the orchestration function only has one await and it is on something that is created with the context.

1

1 Answers

0
votes

Your code is basically the same as the documentation, the only difference is that you are waiting only 10 seconds.

Durable orchestrator functions must be deterministic (https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints) so easily happen tricky errors.

Maybe the run planned using CreateTimer start before current run end and this could explain the "Multithread" exception.

You can try to change code waiting some minutes to verify this. If you need shorter time you can use TimeTrigger instead or a combo of time trigger and scheduled event into a queue (that is the "secret" under durable function :) ).