If your Azure Web App is crashing, the fix usually involves checking the application logs, reviewing the App Service plan’s resource limits, and correcting a misconfiguration in the app settings or deployment. This article walks you through the most common causes and the exact steps to diagnose and resolve them, from simple restarts to scaling adjustments.
Why Azure Web Apps Crash
An Azure Web App crash means the process hosting your code has stopped responding or exited unexpectedly. The root cause often falls into one of these categories:
- Resource exhaustion: The app exceeded its memory (RAM) or CPU quota, and the sandbox killed it.
- Unhandled exceptions: Your code threw an exception that wasn’t caught, crashing the worker process.
- Startup failures: The app failed to start due to a missing dependency, bad connection string, or a port binding issue.
- Configuration errors: Incorrect app settings, connection strings, or a malformed
web.configorapplicationhost.config. - External dependencies: The app couldn’t reach a database, API, or storage account, causing a timeout or fatal error.
- Deployment problems: A bad deploy left the app in an inconsistent state, or the deployment slot swap caused a configuration mismatch.
Step 1: Restart the App (and the App Service Plan)
The quickest fix is often a restart. In the Azure portal, navigate to your Web App, click Restart in the top menu. If the app crashes again immediately, also restart the App Service plan (the pricing tier that hosts your app). This clears any stuck processes or temporary file locks.
If a restart doesn’t help, move to the next step—you need to see why it’s crashing.
Step 2: Check the Diagnostic Logs
Azure captures several types of logs. The most useful for crash diagnosis:
- Application logs: Output from your code (e.g.,
console.log,System.Diagnostics.Trace). Enable them in App Service logs (set to File System or Blob) and then download the logs from the Log stream or via the Kudu console (https://<your-app>.scm.azurewebsites.net). - Web server logs: Raw HTTP requests, useful for spotting a spike in traffic that might have overwhelmed the app.
- Detailed error messages: Turn on Detailed Error Messages and Failed Request Tracing in App Service logs to get stack traces for HTTP 500 errors.
- Crash dumps (Windows): In the portal, under Diagnose and solve problems > Crash Monitoring, you can enable crash dumps. These are memory snapshots that show exactly where the process died.
Look for the last few lines before the crash—they usually contain the exception type and stack trace.
Step 3: Review App Settings and Connection Strings
A common crash cause is a misconfigured setting. In the portal, go to Configuration > Application settings.
- Check for typos: A wrong key name means your code gets
nulland might throw aNullReferenceException. - Validate connection strings: Ensure the server name, database name, and credentials are correct. A common mistake is using the wrong port or SSL mode.
- Look for slot settings: If you use deployment slots, a setting marked as slot setting won’t swap with the slot, causing the app to use the wrong value after a swap.
- Check for the
WEBSITE_RUN_FROM_PACKAGEsetting: If set to1orhttps://..., the app runs from a zip file. If that file is missing or corrupt, the app won’t start.
After changing any setting, the app restarts automatically. If the crash persists, try temporarily removing custom settings to see if one of them is the culprit.
Step 4: Monitor Memory and CPU Usage
If your app runs out of memory, Azure kills it. In the portal, go to Metrics and add charts for Memory working set and CPU time.
Look for a pattern: does memory steadily increase until the crash? That’s a memory leak. Common fixes:
- Dispose of unmanaged resources (database connections, file streams, HTTP clients) properly.
- Use a static
HttpClientinstead of creating a new one per request. - For .NET apps, check for large object heap fragmentation.
- For Node.js, check for global variables that accumulate data.
If the CPU is pegged at 100% for a long time, the app might be stuck in an infinite loop or doing heavy synchronous work. Profile the app with the Application Insights Profiler or a local profiler.
Step 5: Scale Up or Scale Out
If the app is genuinely resource-hungry, you might need a larger App Service plan. In the portal, go to your App Service plan > Scale up to increase the instance size (more RAM/CPU). Or Scale out to add more instances, which distributes the load.
Before scaling, check the Quotas blade on the plan to see if you’ve hit any hard limits (e.g., CPU time, bandwidth, disk space). If you’re on the Free or Shared tier, you have strict quotas—upgrading to a Basic or Standard tier often eliminates crashes caused by quota exhaustion.
Remember: scaling up costs more. Only do it if the metrics show you’re consistently near the limit.
Step 6: Fix Startup Failures
If the app crashes immediately after starting, it’s likely a startup problem. Check the Log stream during startup. Common issues:
- Port binding: Your app must listen on the port provided in the
PORTenvironment variable (for Linux) or the dynamic port for Windows. Hardcoding a port like 8080 will cause a crash. - Missing startup command: For Linux apps, set the correct Startup Command in Configuration > General settings. For example, a Node.js app might need
npm startorpm2 start server.js. - Incorrect runtime version: Ensure the app’s runtime (e.g., .NET 8, Node 18) matches the version your code targets. You can change this in Configuration > General settings > Stack settings.
- Corrupted
web.config: A malformed XML file can prevent the app from starting. Validate it locally or use the Kudu console to view it.
Step 7: Check for External Dependency Timeouts
If your app calls an external service (database, API, blob storage) and that service is slow or down, your app might crash due to a timeout. Look for TimeoutException, SqlException, or HttpRequestException in the logs.
Fix by:
- Adding retry logic with exponential backoff.
- Increasing the timeout in your connection string or HTTP client.
- Using a circuit breaker pattern to fail fast when a dependency is down.
- Checking if the dependency’s firewall or network settings are blocking your app’s outbound IP.
Step 8: Review Deployment and Slots
A bad deployment can crash your app. If the crash started after a deploy:
- Check the deployment logs in Deployment Center.
- Use the Swap with preview feature to test a slot before swapping to production.
- If you use
WEBSITE_RUN_FROM_PACKAGE, ensure the package URL is accessible and the file is not corrupted. - Consider rolling back to the previous deployment using the Deployment slots > Swap or by redeploying the last known-good commit.
Step 9: Enable Always On and Auto-Heal
Two settings can prevent or mitigate crashes:
- Always On: In Configuration > General settings, turn this on. It keeps the app loaded and prevents the sandbox from shutting it down after 20 minutes of inactivity (which can cause a cold start crash if your app isn’t designed for it).
- Auto-Heal: In Configuration > General settings > Auto-heal, you can define rules to recycle the worker process when certain conditions are met (e.g., memory usage > 90% for 5 minutes, or a specific HTTP status code). This doesn’t fix the root cause but can keep the app alive while you diagnose.
Frequently Asked Questions
Why does my Azure Web App crash randomly at night?
Random crashes at night often relate to a scheduled job (e.g., a background task that runs at midnight) that consumes too much memory or hits an external service that’s doing maintenance. Check the logs for the exact time and look for a pattern. Also, if you’re on a Free or Shared tier, the app may be recycled due to idle timeouts—enable Always On to prevent that.
How do I see the crash dump in Azure?
Go to your Web App in the portal, select Diagnose and solve problems, then search for “Crash Monitoring.” Enable crash dumps (for Windows apps) and then reproduce the crash. After a few minutes, you’ll see a list of dump files. Download them and open in Visual Studio or WinDbg to analyze the stack trace.
My app works locally but crashes on Azure. Why?
Differences in environment are the usual cause: a different runtime version, missing environment variables, a different database (local vs. Azure SQL), or file system permissions. Use the Log stream to see the exact error, and compare your local appsettings.json with the Azure Configuration blade. Also, check the PORT environment variable—it’s different on Azure.
What is the difference between “Restart” and “Stop/Start” for an Azure Web App?
Restart recycles the worker process but keeps the same instance. Stop/Start actually deallocates the instance and starts a new one, which can clear more stubborn issues like file locks or stuck sockets. If a restart doesn’t fix a crash, try Stop, wait a minute, then Start.
Can I prevent crashes by scaling out to multiple instances?
Scaling out adds redundancy—if one instance crashes, the load balancer routes traffic to the others. However, it doesn’t fix the underlying code bug or resource leak. You should still investigate the root cause. Also, ensure your app is stateless (no in-memory session data) so any instance can serve any request.
My app crashes after a slot swap. What should I check?
Slot swaps are a common source of crashes. Check that all settings you expect to swap are not marked as “slot settings.” Also, verify that the staging slot has the correct connection strings and app settings. A common mistake is having a different runtime version or a missing startup command in the staging slot. Use Swap with preview to test before finalizing.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- MacBook Charger Not Working? Fix It Now
- Fix Windows Cannot Be Installed to This Disk
- Zoom on iPhone & iPad: Host or Join a Meeting
- Fix iPhone SE 4 Unable to Activate: Step-by-Step
- Keep Important Emails From Getting Buried in iPhone Mail Categories
- How to Clear RAM on iPhone: Speed It Up