Hi @Kashif Hanif,
Thanks for the question and using MS Q&A platform.
It seems like you've done a thorough job testing and researching the behavior of Azure App Service on Linux about idle timeouts as well as graceful shutdown.
- Idle Timeout on Linux App Service:
- By Design: Azure App Service on Linux does not implement an idle timeout mechanism (unlike Windows). Containers remain active indefinitely unless explicitly stopped by lifecycle events (e.g., scaling, redeployments).
- SIGTERM Behavior: SIGTERM is only sent during intentional shutdown events (scale-in, manual stop, deployment). No SIGTERM is triggered by inactivity.
- Official Documentation & Community Evidence:
- No official Azure documentation confirms idle timeout support on Linux. The below mentioned first link emphasizes that "Always On" prevents unloads but does not mention idle termination.
- Linux containers persist until explicitly stopped.
- Workarounds for Cost Reduction:
- Auto-Scaling to Zero: Use Azure Automation or Logic Apps to programmatically scale your App Service Plan (ASP) to zero instances during idle periods. Note:
- Drawback: Billing continues for the underlying VM if using non-Dev/Test plans (e.g., Premium).
- Alternative: Use a Consumption Plan (Azure Functions/Container Apps) for true pay-per-use.
- Shutdown Schedules: Schedule start/stop times via Azure CLI/PowerShell (e.g., off-hours).
- Custom Idle Detection: Implement application-level logic to self-terminate after inactivity (e.g., track last request time, exit process if idle). Use "docker stop" commands via Azure CLI in a sidecar process.
- Switch to Azure Container Apps: Offers scale-to-zero natively with HTTP traffic triggers.
KeyPoint's:
- Linux App Service lacks native idle timeout; design your architecture assuming containers run perpetually unless actively managed.
- Prioritize scaling automation or serverless options if cost optimization is critical for low-traffic apps.
App Service on Linux FAQ | Microsoft Learn
Scale up features and capacities - Azure App Service | Microsoft Learn
Scaling in Azure Container Apps | Microsoft Learn
Please, do refer the above link
Hope the above provided information help in better understanding and help you resolve the issue, if you have any further concerns or queries, please feel free to reach out to us.
If the answer is helpful, please click Accept Answer and kindly upvote it so that other people who faces similar issue may get benefitted from it.