Azure / Azure/azure-functions-host

Allow a function to handle execution timeout gracefully and prevent process restart

Open
#2,153 13 comments 17 reactions 0 assignees View on GitHub
2.x enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 11h
Merged PRs (30d)
37

Description

So the consumption plan for functions has a default execution timeout of 5 minutes. Its not great to allow your functions to hit this timeout because when it happens, your entire process ends up getting restarted (because its the only way to force the execution to stop - `task.Abort()` does not exist). This will be disruptive to other long running functions in the same process.

The challenge is that as a function author that is aware of this, there's not much you can do to address it. In the case of C#, you could update your function to take a `CancellationToken` and check the state of that token (or pass it into async APIs your function is calling). However even if you do this, today the system will still terminate the process (because it does not check to see if your function actually honored the cancellation request).

So, this work item tracks the idea of making the timeout mechanism smarter. It would do the following:
1. If the function does not take a cancellation token, no change in behavior (the process will get killed)
2. If the function takes a cancellation token, signal the token once the timeout has expired and then wait some period of time (say 5 seconds) and then check to see if the function task has completed. If the task has completed then we assume the timeout was handled gracefully and do not kill the process.

In order for this approach to work for multiple languages, we need a way to support the equivalent of cancellation tokens for out of proc languages which is tracked by https://github.com/Azure/azure-webjobs-sdk-script/issues/2152.

Contributor guide

Open the contributing guide

Research direction

Start by reading the linked issue 2152, then trace the host's function-timeout handling and the C# CancellationToken path. Done means a token-aware function can finish after timeout without restarting the process, while functions without a token retain the existing termination behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.