Multiple orchestrators in a durable function can start running due to several reasons. One common cause is the replay behavior of orchestrator functions, which use event sourcing to ensure reliable execution and maintain local variable state. If an orchestrator function fails or times out, it will re-execute from the last successful checkpoint, which could lead to multiple orchestrators running if not managed correctly.
Additionally, if the code is not idempotent, meaning it does not produce the same result if executed multiple times, this can also cause multiple orchestrators to start. It’s important to ensure that the orchestrator code is idempotent and to manage the checkpoints and history table storage carefully to prevent multiple instances from running simultaneously.
It's difficult to know exactly what issue you may be running into. In the code you provided, if the TestFileOrchestrator
is triggered multiple times, due to the timer trigger or manual invocation, and if the previous instances have not completed their execution, it could lead to multiple instances running. To prevent this, you can check if an instance is already running using the IDurableOrchestrationClient
and manage new invocations accordingly. Also, ensure that the TestTTFunction
timer trigger is not set to a frequency that overlaps with the duration of the TestFileOrchestrator
execution to avoid concurrent runs. When activity functions are triggered and run in parallel, multiple orchestration instances can be created if each activity function invocation leads to a new orchestration instance being started. This can happen if the orchestration client is used within the activity functions to start new orchestrators, which should typically be avoided. I don't believe this is happening, but without knowing what's happening in _TestService.SendTestMessageAsync
, I wanted to make this callout. You could be running into concurrence issues with activity functions not being synchronized or incorrect use of external events if they are inadvertently being sent to the orchestrator.
If you haven't done so already, there is a Durable Functions detector under Diagnose and solve problems blade that may provide insights on the execution flow of the orchestration. If not, let me know down below.