1
votes

I have an OrchestrationTrigger function that call another service by http request.

 [FunctionName("MyFunc")]
        public async Task RunOrchestrator(
        [OrchestrationTrigger] IDurableOrchestrationContext context,
        ILogger logger)
    {
        var req = new DurableHttpRequest(HttpMethod.Post, _uri, headers, jsonBody);
        var res = await context.CallHttpAsync(req);
        // Do something
    }

but get the following 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. More details can be found in this article https://docs.microsoft.com/en-us/azure/azure-functions/durable-functions-checkpointing-and-replay#orchestrator-code-constraints.

the official documentation there suggest to use context.CallHttpAsync - exactly what I've did.

2

2 Answers

2
votes

When a IDurableOrchestrationContext method throws this exception, it means that you called the method using a thread other than the orchestrator thread. The problem here isn't necessarily with the CallHttpAsync call, but rather the fact that something else in your code spun up a new thread. In most cases, this is caused by an illegal await statement in some previous line of code - e.g. await Task.Delay(1000).

If you can update your post with your full orchestration description, then we should be able to more easily point out where the problem is.

Also, consider using the Durable Functions Roslyn Analyzer to help detect these types of coding mistakes proactively (there will be a new version available later this week which fixes a bunch of known issues).

0
votes

I've upgraded Microsoft.Azure.WebJobs.Extensions.DurableTask and Microsoft.NET.Sdk.Functions and the issue disapeared