Graceful shutdown of app service on Linux

Ad Gaasbeek 0 Reputation points
2025-01-31T09:11:04.2233333+00:00

I have a Azure App Service (Linux, Java).

When I scale down the number of instances, my application gets killed immediately. However, this leads to transaction errors and database locks. What I want to accomplish is to detect the shutdown, and being able to finish the ongoing work (while not starting any new processes and let my health-check return 503)/

I am able to detect receiving the TERM signal and starting my shutdown process. But Azure does not wait for this to complete, but apparently decides to immediately kill the application.

How can I make Azure to wait killing my application until I say my application is ready for it?

PS When stopping my application, it also does not respect the handling of the TERM signal, and kills immediately.

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

1 answer

Sort by: Most helpful
  1. Laxman Reddy Revuri 2,315 Reputation points Microsoft Vendor
    2025-01-31T12:21:48.9466667+00:00

    Hi @Ad Gaasbeek
    Thanks for the question and using MS Q&A platform.
    Unfortunately, Azure App Service does not provide a built-in mechanism to extend the shutdown timeout beyond the default behavior, which may lead to immediate termination of your application. Therefore, you may need to handle the shutdown logic within your application to minimize the impact of abrupt terminations.

    Additionally for smooth shut down your Azure App Service on Linux, make sure to handle the TERM signal properly. Keep in mind that Azure App Service doesn't automatically wait for your app to finish shutting down before it terminates.

    Set up health probes to manage the app's state during the shutdown. By returning a 503-status code from your health checks when you get a shutdown signal, you can stop new requests while letting ongoing tasks wrap up. But note, Azure might still enforce a timeout period and forcibly terminate your app if it exceeds this period.

    1.Implement signal handling to catch the TERM signal.

    2.Use health probes to show when the app isn't ready for new traffic.

    3.Ensure the app finishes ongoing transactions before the timeout hits.
    references:
    https://learn.microsoft.com/en-us/azure/spring-apps/basic-standard/how-to-configure-health-probes-graceful-termination?tabs=azure-portal#health-probe-properties
    Please accept as "Yes" if the answer provided is useful, so that you can help others in the community looking for remediation for similar issues.


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.