"MultiThreaded Execution was detected" Azure Orchestrator 函数中的错误

"MultiThreaded Execution was detected" error within Azure Orchestrator Function

我正在尝试按照此处列出的代码作为示例,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,用于在持久函数中创建永恒的编排。

目前,我有一个 HTTP 触发函数

[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);
}

编排触发器函数为

[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);
}

现在我只是想看看永恒的编排工作(每 10 秒查看一次打印)但是只执行一次后我总是得到错误:

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

鉴于编排函数只有一个等待并且它是在使用上下文创建的东西上,我不确定错误到底是什么基于消息。

你的代码和文档基本一样,唯一的区别就是你只等了10秒。

持久协调器函数必须是确定性的 (https://docs.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-code-constraints),因此很容易发生棘手的错误。

也许 运行 计划在当前 运行 结束之前使用 CreateTimer 启动,这可以解释“多线程”异常。

您可以尝试更改代码等待几分钟来验证这一点。 如果你需要更短的时间,你可以使用 TimeTrigger 代替,或者将时间触发器和计划事件组合到一个队列中(这是持久函数下的“秘密”:))。