ERROR

Windows IIS Application Pool: Fix Intermittent 503 Service Unavailable Timeouts

Quick Fix Summary

TL;DR

Recycle the affected application pool and verify the worker process is running.

Intermittent 503 errors with Event ID 15021 indicate the IIS worker process (w3wp.exe) for the application pool is crashing, failing to start, or being terminated, often due to resource exhaustion, application errors, or configuration issues.

Diagnosis & Causes

  • Application pool identity permissions or password expiration
  • Rapid-Fail Protection triggering due to repeated crashes
  • Memory leaks or excessive CPU usage causing worker process termination
  • Recovery Steps

    1

    Step 1: Verify Application Pool State and Event Logs

    Check the current state of the application pool and review recent System and Application event logs for errors related to the crash.

    powershell
    # Check Application Pool state
    Get-WebAppPoolState -Name "YourAppPoolName"
    # Check for recent Event ID 15021 or 5002 errors
    Get-EventLog -LogName System -Source "WAS" -Newest 20 | Format-List
    Get-EventLog -LogName Application -Newest 20 | Where-Object {$_.Source -like "*ASP.NET*" -or $_.Source -like "*IIS*"} | Format-List
    2

    Step 2: Recycle Application Pool and Restart IIS

    Immediately restart the application's worker process. If the issue persists, perform a full IIS reset.

    powershell
    # Recycle the specific Application Pool
    Restart-WebAppPool -Name "YourAppPoolName"
    # Full IIS Reset (if needed)
    iisreset /noforce
    3

    Step 3: Check and Adjust Rapid-Fail Protection Settings

    If the worker process is crashing repeatedly, Rapid-Fail Protection may be disabling the pool. Review and temporarily adjust its thresholds.

    powershell
    # View current Rapid-Fail Protection settings for the pool
    Get-ItemProperty "IIS:\AppPools\YourAppPoolName" -Name failure.* | Format-List
    # Temporarily increase failure limits for troubleshooting
    Set-ItemProperty "IIS:\AppPools\YourAppPoolName" -Name failure.rapidFailProtectionInterval -Value 00:05:00
    Set-ItemProperty "IIS:\AppPools\YourAppPoolName" -Name failure.rapidFailProtectionMaxCrashes -Value 20
    4

    Step 4: Review Application Pool Identity and Permissions

    Ensure the application pool identity (e.g., a specific service account) has not expired and has correct permissions on the site's directories.

    powershell
    # Check the pool's identity (run as Administrator)
    Get-ItemProperty "IIS:\AppPools\YourAppPoolName" -Name processModel | Select-Object userName, password
    # Verify key folder permissions (e.g., site root, temp directories)
    icacls "C:\inetpub\wwwroot\YourSite" /T
    5

    Step 5: Analyze Worker Process Memory and CPU

    Identify if the w3wp.exe process is consuming excessive resources, leading to termination by IIS or the OS.

    powershell
    # Find the PID and monitor resource usage for the specific app pool's w3wp
    Get-Process w3wp | Where-Object {$_.ProcessName -eq "w3wp"} | Select-Object Id, CPU, WorkingSet, PM, ProcessName
    # Monitor for a short period (adjust -Seconds)
    Get-Counter "\Process(w3wp*)\% Processor Time" -SampleInterval 2 -MaxSamples 5
    6

    Step 6: Enable and Review Failed Request Tracing (FREB)

    Enable tracing for 503 errors to capture a detailed log of the request and process state at the moment of failure.

    text
    # 1. Enable Failed Request Tracing in IIS Manager for the site (UI).
    # 2. Add a trace rule for Status Code 503.
    # 3. Reproduce the error, then find the trace file at:
    # %SystemDrive%\inetpub\logs\FailedReqLogFiles\W3SVC<ID>\

    Architect's Pro Tip

    "This often happens when a 3rd-party application pool uses a custom service account with a group-managed password that has expired. Always check the account status in Active Directory and ensure 'Log on as a service' right is assigned. Also, monitor for 'OutOfMemoryException' in .NET application logs, which can cause silent worker process crashes."

    Frequently Asked Questions

    The pool recycles but 503s return after a few minutes. What's next?

    This pattern strongly indicates an application-level memory leak or unhandled exception causing the worker process to crash. Enable Debug Diag or ProcDump to capture a memory dump of w3wp.exe at the moment of crash and analyze it with WinDbg or examine .NET application logs for fatal errors.

    Can antivirus or security software cause this?

    Yes. Real-time scanning of the application's .NET temporary files (in the 'Temporary ASP.NET Files' folder) or the site's .dll files can cause high CPU, file locks, and process instability. Add exclusions for your site's directories and the ASP.NET temp folders in your antivirus software.

    Related Windows Guides