Is Idle Timeout / Auto-Shutdown (SIGTERM) Supported for Azure App Service on Linux?

Kashif Hanif 20 Reputation points
2025-02-02T06:36:08.8466667+00:00

Hello everyone,

I’m trying to understand the behavior of idle timeout and graceful shutdown in Azure App Service when running on Linux. I have a .NET (or any other default template) app deployed on Azure App Service using a Linux container. Here’s a summary of my observations and questions:

  1. Expected Behavior on Windows vs. Linux:

– On Windows App Service, when “Always On” is disabled, the platform automatically unloads an idle app (typically after around 20 minutes of inactivity). This auto-unload triggers a graceful shutdown signal (SIGTERM) to the application, allowing it to complete cleanup tasks.

– In contrast, my tests on Linux (using the default template code) show that the container continues running indefinitely—even with “Always On” off—and no SIGTERM is received due to inactivity.

  1. SIGTERM for Graceful Shutdown:

– I understand that Linux containers do support receiving SIGTERM for graceful shutdown when the container is actually stopped (for example, during a scale-down, redeployment, or manual stop). I have implemented signal handlers in my application to catch SIGTERM for cleanup. However, in the idle scenario (with no incoming traffic), the app never receives SIGTERM; it just keeps running. – I came across a discussion (e.g., via DeepSeek R1) suggesting that idle shutdown might be supported via SIGTERM on Linux. Yet, I couldn’t find any official documentation that confirms an idle timeout mechanism (like on Windows) for Linux App Service.

  1. My Testing Details:

– I deployed a new app (using the default .NET template) to an Azure App Service on Linux.

– I disabled “Always On” in the portal expecting, based on Windows behavior, that after a period of inactivity (around 20 minutes) the container might be unloaded and receive a SIGTERM for graceful shutdown.

– Instead, the container remained active and no SIGTERM (or any shutdown signal) was triggered by inactivity. – I have searched through documentation such as the Azure App Service on Linux FAQ and the GitHub “Things You Should Know” document for Linux App Service, but couldn’t find any explicit reference to an idle timeout or auto-shutdown behavior on Linux.

My Questions to the Community:

Is the absence of an idle timeout (and associated SIGTERM signal) on Linux App Service by design?

Does Azure provide any hidden or undocumented configuration that would allow an idle Linux container to be automatically shut down (similar to Windows)?

Have you seen any official confirmation or community evidence that Linux App Service supports unloading an idle app via SIGTERM?

For use cases where resource cost reduction is desired via idle shutdown, what workarounds have you implemented in a Linux container scenario?

I’d appreciate any insights, references, or experiences you can share regarding this topic. Thank you for your help.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,258 questions
{count} votes

Accepted answer
  1. Bhargavi Naragani 575 Reputation points Microsoft Vendor
    2025-02-06T08:29:49.1+00:00

    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.

    1. 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.
    1. 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.
    1. 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.