<p>I am running a KEDA enabled Queue Triggered Azure Function for which <code>terminationGracePeriodSeconds</code> has been set to <code>900</code> seconds (15 minutes).  The function execution time varies between 30 seconds and 600 seconds (10 minutes). So grace period of 15 minutes seems to be reasonable.</p>
<p>Is there a possibility that after the SIGTERM is issued, the pod takes up a new request after finishing the current one if there is still some grace period left.</p>
<p>I have come across situations where the function execution stops abruptly, leaving the message unprocessed.</p>
<p>Here are the specifications in the deployment:</p>
<pre><code>spec:
      containers:
        - image: ####.azurecr.io/azurefunctionqueuetriggeredk8s
          name: queuetrigcontainer
          ports:
          - containerPort: 80
          resources:
            requests:
              memory: &quot;500Mi&quot;
              cpu: &quot;700m&quot;
            limits:
              memory: &quot;600Mi&quot;
              cpu: &quot;700m&quot;
      nodeSelector:
        agentpool: testuserpool
      terminationGracePeriodSeconds: 900
</code></pre>
<p>Is there any plausible explanation for this behavior? How this can be resolved?</p>
<p>EDIT:
The container logs show &quot;Application is shutting down...&quot;</p>
<p><a href="https://i.stack.imgur.com/pGg5a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pGg5a.png" alt="enter image description here" /></a></p>

<p>Looks like this is a non-implemented event on the code side, and not necessarily something related to your configuration.
The most probable explanation is the SIGTERM is not handled and the function keeps processing events, no matter what.</p>
<p>There are reports here on GitHub (<a href="https://github.com/Azure/azure-functions-host/issues/5365" rel="nofollow noreferrer">https://github.com/Azure/azure-functions-host/issues/5365</a>) about kind of the same situation with a timeout.</p>
<p>If you have the chance you could handle the <code>ApplicationStopping</code> and <code>ApplicationStopped</code> events on the <code>IApplicationLifetime</code> object and stop the function from processing if the app is in a stopping state.</p>
