Michael
Michael

Reputation: 3071

Azure Function MaxAutoRenewDuration ignored

I have an Azure Function (Consumption Plan) triggered by a service bus queue.

I set maxAutoRenewDuration in host.json

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "messageHandlerOptions": {
        "maxAutoRenewDuration": "00:10:00"
      }
    }
  },
  "functionTimeout": "00:10:00"
}

The expectation is that message lock will be renewed up to 10 minutes. However, if I look at function execution logs, I see message lock expires every 5 minutes, effectively retriggering the function.

The execution logs:

enter image description here

As can be seen from the logs, function executes exactly after 5 minutes (when the lock expires). I'd expect to see function being re-triggered every 10 minutes (assuming ofc function execution is not done yet).

This is my function:

[FunctionName(nameof(MyFunc))]
public async Task MyFunc(
    [ServiceBusTrigger(queueName: "myqueue", Connection = "ServiceBusConnectionString")]
    Message message,
    ILogger logger,
    ExecutionContext executionContext)
{
    var invocationId = executionContext.InvocationId;

    // long running processing, that sometimes can stretch beyond 5 minutes
    await Process(invocationId, message);
}

How can I set auto renew duration, so that message lock being renewed until configured time ?

Azure Function v3, running .net core 3.1. OS: Windows

Upvotes: 1

Views: 1050

Answers (1)

Michael
Michael

Reputation: 3071

It looks that in my case no need to set MaxAutoRenewDuration. Revisiting PeekLock behavior documentation

The Functions runtime receives a message in PeekLock mode. It calls Complete on the message if the function finishes successfully, or calls Abandon if the function fails. If the function runs longer than the PeekLock timeout, the lock is automatically renewed as long as the function is running.

I have functionTimeout configured in host.json, which is set to 10 minutes. So as long as function executes, message lock will be automatically renewed. I removed maxAutoRenewDuration from host.json and now function doesn't execute after message lock expiration.

Upvotes: 1

Related Questions