title: How does message locking and lock renewal work in Azure Service Bus?
body: <p>I'm getting a bit confused trying to nail down how peek lock works in Service Bus. In particular I'm using Microsoft.Azure.ServiceBus with Azure Functions and a ServiceBusTrigger.</p>
  <p>From what I can make out the time a message gets locked for is set on the queue itself and defaults to 30 seconds though it can be set to be anywhere up to 5 minutes.</p>
  <p>When a message is peeked from the queue this lock kicks in.</p>
  <p>There is then a setting called maxAutoRenewDuration which when using Azure Functions is set in the host.json file under Extensions:ServiceBus:messageHandlerOptions.  This allows the client to automatically request one or more extensions to a lock until the maxAutoRenewDuration is reached. Once you hit this limit a renewal won't be requested and the lock will be released.</p>
  <p>Renewals are best effort and can't be guaranteed so ideally you try to come up with a design where messages are typically processed within the lock period specified on the queue.</p>
  <p>Have I got this right so far?</p>
  <p>Questions I still have are</p>
  <ol>
  <li>are there and limits on what maxAutoRenewDuration can be set to. One article I read seemed to suggest that this could be set to whatever I need to ensure my message is processed (<a href="https://markheath.net/post/azure-service-bus-messaging-6" rel="noreferrer">link</a>).  The Microsoft Documentation though states that the maximum value for this is also limited to 5 minutes (<a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus-trigger?tabs=csharp#peeklock-behavior" rel="noreferrer">link</a>).</li>
  </ol>
  <blockquote>
  <p>The maxAutoRenewDuration is configurable in host.json, which maps to OnMessageOptions.MaxAutoRenewDuration. The maximum allowed for this setting is 5 minutes according to the Service Bus documentation</p>
  </blockquote>
  <p>Which is correct?  I know the default lock duration has a maximum of 5 minutes but it doesn't seem to make sense that this also applies to maxAutoRenewDuration?</p>
  <ol start="2">
  <li><p>I've read about a setting called MaxLockDuration in some articles (e.g. <a href="https://weblogs.asp.net/sfeldman/understanding-Azure-service-bus-prefetch" rel="noreferrer">link</a>).  Is this just referring to the lock duration set on the queue itself?</p>
  </li>
  <li><p>Am I missing anything else?  Are the lock duration set on the queue and the maxAutoRenewDuration in my code the main things I need to consider when dealing with locks and renewals?</p>
  </li>
  </ol>
  <p>Thanks</p>
  <p>Alan</p>