I need to avoid indefinite number of retries of durable function orchestrations

Anil Bhat 20 Reputation points
2025-02-18T22:47:35.7333333+00:00

I wrote an Azure Function App with Durable Functions. While testing with a large dataset, I realized that the functionTimeout value was 10 mins. This caused some of the orchestrations to timeout. Thus began an indefinite number of retries of the failed orchestrations. I have increased the timeout setting to 1 hour 30 mins, but some of the old retries are still pending and therefore still running. I have tried stopping the function app and restarting it back up, but the execution of the orchestrations continued. I have also tried constructing the terminatePostUri query string but I see an HTTP 404 error.

Two questions:

  1. How do I stop the execution of the orchestrations?
  2. How do I set the number of retries of the orchestrations (not the activity calls) to 0?
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,441 questions
0 comments No comments
{count} votes

Accepted answer
  1. Chiugo Okpala 545 Reputation points MVP
    2025-02-19T05:19:20.3833333+00:00

    @Anil Bhat

    To stop the execution of the orchestrations, you can use the TerminateAsync method provided by the IDurableOrchestrationClient interface. This method allows you to terminate a running orchestration instance. Here's an example of how you can use it:

    [FunctionName("TerminateOrchestration")]
    public static async Task<IActionResult> TerminateOrchestration(
        [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
        [DurableClient] IDurableOrchestrationClient client,
        ILogger log)
    {
        string instanceId = req.Query["instanceId"];
        string reason = req.Query["reason"];
    
        await client.TerminateAsync(instanceId, reason);
        return new OkResult();
    }
    

    You can call this function with the instance ID of the orchestration you want to terminate and a reason for the termination.

    To set the number of retries of the orchestrations to 0, you can configure the retry policy for the orchestrator function. By default, orchestrator functions do not retry on failure. However, if you have configured a retry policy, you can set the maximum number of attempts to 1 to effectively disable retries. Here's an example of how you can configure the retry policy:

    var retryOptions = new RetryOptions(
        firstRetryInterval: TimeSpan.FromSeconds(5),
        maxNumberOfAttempts: 1 // Set to 1 to disable retries
    );
    
    await context.CallActivityWithRetryAsync("ActivityFunctionName", retryOptions, input);
    

    This will ensure that the orchestrator function does not retry on failure.

    I hope this helps. Let me know if you have any other questions.

    See:


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.