Open
Description
We use the Function App to process time-consuming operations including heavy database queries & sending large files to some 3rd party. We host them using dotnet-isolated
runtime in Azure Kubernetes Services (AKS) using the official Docker image . Sometimes execution of the function takes 1-2 minutes and it's quite undesired to stop it in the middle of processing. It looks like the proper approach to maximize the chance that the function finishes the execution is to drain the function host on exiting.
After some research, I found that there is the FUNCTIONS_ENABLE_DRAIN_ON_APP_STOPPING
environment variable enabling this feature but then I encountered another issues:
- The Docker container doesn't pass the termination signal to the dotnet host function because it uses the bash wrapper. I've tried to correct it in the Correct dotnet entrypoint script to run the function host as the main process azure-functions-docker#1023
- I didn't find a way to override the ProcessShutdownTimeout. Is there way to do this?
- The drainModeManager.EnableDrainModeAsync(CancellationToken.None) didn't finish before the process exists. I've tried to fix it by Await EnableDrainModeAsync if DrainOnApplicationStoppingEnabled #9780 but then I checked it and it also didn't help. After that I've tried calling this synchronously:
and now it waits till the function really finishes
drainModeManager.EnableDrainModeAsync(CancellationToken.None).GetAwaiter().GetResult();