Resolving Azure App Service startup failures

Azure App Service is a fully managed platform-as-a-service (PaaS) offering from Microsoft Azure. It supports various programming platforms, including .NET Framework and .NET Core, and features built-in infrastructure, security patching, and scaling. The service enables developers to build, deploy, and scale web applications and APIs easily, making it useful to host .NET applications.

However, despite its helpfulness, users may encounter issues using Azure App Service, including startup failures like HTTP errors, process crashes, and application-level errors. These failures can lead to dissatisfied customers and financial loss.

This article discusses common App Service startup failures, their consequences, and how you can troubleshoot them.

Understanding Azure App Service startup failures

When working with Azure App Service, developers are likely to encounter three common types of startup failure:

  • HTTP errors — These occur due to misconfigurations, code errors, or dependency issues. HTTP errors can lead to degraded user experience and reputational damage.
  • Process crashes — Memory leaks or unhandled exceptions are usually the culprits here. They can result in application unresponsiveness, downtime, and possible data loss.
  • Application-level errors — These include bugs and incorrect data processing. They can lead to incorrect outputs, data corruption, security vulnerabilities, and system failures.

While these are not the only potential causes of startup failures, your typical startup failure typically falls into one of these categories. Each of these failures can impact the deployment and performance of a .NET application—reducing scalability, diminishing user experience, increasing response times, and disrupting availability. Let’s explore how to resolve them.

Addressing HTTP errors in Azure App Service

When an HTTP request fails, the web server returns an HTTP error—a three-digit status code that tells you what went wrong. Perhaps the client’s request was incorrect or unsupported, or there was an error in the code or unfindable resources.

Some errors can directly impact the functionality of the application you have hosted on the Azure App Service. For example, client errors (4xx) can prevent users from accessing certain resources or performing specific actions, and server errors (5xx) can cause the application to crash or become unavailable. HTTP errors, like 400 Bad Request or 503 Service Unavailable, negatively impact the user experience.

If your application frequently returns these errors, especially 4xx, it can adversely affect your search engine rankings and site indexing. Search engines will interpret frequent errors as evidence that your site is unreliable and reduce your visibility in search results accordingly.

You can use App Service Diagnostics to diagnose HTTP errors in Azure App Service. First, open the Azure portal and navigate to your Azure App Service. In the left-hand menu, click Diagnose and solve problems to open the App Service Diagnostics blade.

Azure Portal displaying the App Service Diagnostics blade Fig. 1: Azure Portal displaying the App Service Diagnostics blade

Now, in Troubleshooting categories, click Availability and Performance. This page will display recent HTTP status codes your app encountered, along with an overview of the error distribution and the most common error codes, like the screenshot below.

Azure Portal displaying the Availability and Performance blade Fig. 2: Azure Portal displaying the Availability and Performance blade

In the example here, when you hover over the 05:15 point on the timeline (as the bottom of the image above shows), you’ll learn that the following HTTP codes were returned:

  • Http2xx (success): 2 occurrences
  • Http4xx (errors): 2 occurrences
Details showing the number of returned HTTP codes by type Fig. 3: Details showing the number of returned HTTP codes by type

Ten minutes later, at 05:25, there were three occurrences of HTTP5xx errors:

Request counts for each of the resulting HTTP codes over time Fig. 4: Request counts for each of the resulting HTTP codes over time

Now, click the FailedRequests tile (highlighted on the left in the image below) to open the Web App Down blade.

From there, the Observations and Solutions expandable panel lists the various errors, giving you basic information about each and options to investigate them further. For example, the image below shows .Net Core startup failures, HTTP Server Errors, Web App Restarted, Application Changes, and HTTP 4xx Errors.

Observations and Solutions panel Fig. 5: Observations and Solutions panel

Click View Details on .NET Core Startup Failures to open a blade with recommended steps. In this case, it recommends inspecting the exceptions in the Application Exceptions table to determine if the errors result from user code and using the Code Snippet or Exception Message to determine the cause of the exceptions. The details also note that the application will be down until you resolve the exceptions.

Exception details from a .NET Core startup failure Fig. 6: Exception details from a .NET Core startup failure

Expand HTTP Server Errors for more information about the errors and troubleshooting methods, like the screenshot below.

Details from an HTTP server error Fig. 7: Details from an HTTP server error

Click View Details to identify all the failed requests for the app and some standard solutions to resolve these errors. In the example above, HTTP Error 500.30 typically indicates an issue with the underlying ASP.NET Core runtime configuration in Azure App Service. Always ensure your application runs the .NET version that Azure App Service targets.

Expand HTTP 4xx Errors for more information about the 4xx errors the app encountered. In this case, as the screenshot below shows, there were two 404 errors where the requested resource was not found.

Details from an HTTP 404 error Fig. 8: Details from an HTTP 404 error

Now, click View Details to view all the HTTP 4XX requests for the app. This screen also offers some standard methods to investigate and resolve HTTP 4XX errors, which can result from incorrect URLs, connection strings, or missing resources. So, take the time to ensure that the requested resources exist and are properly referenced.

Troubleshooting process crashes in Azure App Service

Process crashes significantly impact Azure App Service startup, causing the app service to shut down. When a process within the app service crashes, it fails to execute its tasks, triggering a chain reaction that can affect the service’s stability and functionality. By carrying out effective diagnosis and remediation whenever you experience a process crash, you can optimize the stability of your Azure App Service.

Take the following steps to diagnose process crashes using Azure's log streaming service and application diagnostics:

  • Enable and configure the Azure portal settings.
  • Enable log streaming to view real-time logs from your Azure App Service.
  • Monitor the log stream for errors or warnings related to process crashes, analyze specific log entries, and look for unexpected terminations or stack trace information.
  • Configure your application diagnostics to collect dump files when a crash occurs and review them offline using appropriate debugging tools.
  • Leverage Azure Monitor and Application Insights to gather telemetry data, set up alerts, and receive real-time notifications when process crashes occur.

Here are some practical solutions to fix process crashes in Azure App Service:

  • Update dependencies and libraries — Outdated or incompatible dependencies and libraries can often lead to process crashes.
  • Optimize resource allocation — Insufficient resources allocated to your Azure App Service can cause process crashes, especially if your application experiences a high load or requires significant memory or CPU usage.
  • Implement robust error handling and logging — Inadequate error handling and logging mechanisms can make identifying and resolving process crashes challenging.

Enabling application logging

To enable logging, navigate to App Service Logs under Monitoring on the left pane:

App Service Logs on the Web App resource Fig. 9: App Service Logs on the Web App resource

You can enable logging into the Web App’s file system or a blob storage container. For this exercise, set Application Logging (Filesystem) to on and the Level to Error:

Configuring Application Logging and Detailed error messages Fig. 10: Configuring Application Logging and Detailed error messages

Remedying application-level errors in Azure App Service

Application-level errors occur within the application code. When an application fails to handle a problem that it encounters and cannot recover from the failure, the app service can unexpectedly crash or shut down. There are several possible causes for these errors, including bad programming practices, errors and exceptions arising from the code during runtime, and configuration problems.

Application-level errors are frustrating for both developers and users. So, to maintain good uptime and reliability, you must quickly identify and address them.

Diagnostic tools such as Azure Application Insights and Azure Log Analytics enable you to identify application-level errors with detailed logs, metrics, and telemetry data. With these logs, you can pinpoint code-level issues such as exceptions, bugs, and incorrect data processing, along with configuration problems, like misconfigured dependencies or incorrect settings. You can then debug, implement proper error handling, or improve data validation to fix the underlying code issues. Updating configuration settings, ensuring accurate connection strings, or adjusting dependencies can also help resolve configuration problems.

Best practices to avoid startup failures in Azure App Service

Follow these best practices to avoid common startup failures in Azure App Service:

  • Perform regular diagnostics: Use Azure Application Insights, or a similar monitoring tool, to analyze application performance data and detect anomalies, so you can promptly address them.
  • Perform comprehensive error logging: Implement robust error logging mechanisms to capture detailed error information. Analyze logs regularly to identify recurring patterns or trends that could indicate underlying issues.
  • Adhere to coding standards: Conduct regular code reviews, perform testing, and use static code analysis tools. They can help you identify code errors, security vulnerabilities, and performance bottlenecks early in the development lifecycle.
  • Adhere to configuration standards: Maintain accurate and up-to-date configuration settings, connection strings, and environment variables. Avoid hardcoding sensitive information and employ secure configuration storage mechanisms.
  • Implement continuous integration and deployment: Implement a robust continuous integration and continuous delivery (CI/CD) pipeline to automate the deployment process and ensure consistency across multiple environments.

Conclusion

This article examined the common causes of HTTP errors, process crashes, and application-level errors. We looked at the best practices to avoid startup failures, including proper configuration and dependencies, error handling and logging mechanisms, monitoring application health, regular testing and validation, and enabling CI/CD for seamless updates.

To troubleshoot a startup failure in Azure App Service, you need to fully understand the causes of that failure. By following the steps outlined in this article, you can diagnose and resolve startup failures, improving the overall performance and stability of your Azure App Service.

Was this article helpful?

Related Articles

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 "Learn" portal. Get paid for your writing.

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.

Apply Now
Write For Us