Troubleshooting IIS7 503 "Service unavailable" errors with startup debugging

In a previous post titled Where did my IIS7 server go? Troubleshooting "service unavailable" errors, I covered the basic steps for dealing with cases where the IIS7 web server fails to process the request.  This error mostly occurs whenever HTTP.SYS, the kernel HTTP driver that manages http connections for IIS, fails to create an IIS worker process to process the request.

This failure is typically caused by a critical error during worker process initialization, or more likely an unhandled exception / access violation occurring during worker process startup.  The most common instance of this is a module AVing inside its RegisterModule function during worker process initialization.  It can also be caused by the process going away due to an unhandled exception / AV during the processing of the request that causes the process to be torn down. 

After a certain number of failures, the application pool will trigger Rapid Fail Protection, a WAS feature designed to stop application pools with a persistent failure condition to avoid an endless loop of failing to start worker processes.  At this point, all requests to applications within the stopped application pool will result in the 503 error, and the application pool will need to be re-started manually.

My previous post covers the steps necessary to diagnose most of the error conditions that may cause 503 errors.  In most of these cases, there should be an event log event in the "Application" event log that indicates why the worker process has terminated.

However, in the case of an unhandled exception or AV, you may need to run the worker process under a debugger to get more information about the error.  This can give you critical insight into the problem, including the DLL causing the exception, and the exception stack trace, which you can then use to remove the offending module, or provide details to the developer to fix the problem.

1) First, you need to download and install the latest debugging tools.

2) Restart the application pool if it entered RFP (rapid fail protection) and is currently stopped:

> %windir%\system32\inetsrv\appcmd start apppool <APPPOOLNAME>

Where <APPPOOLNAME> is the name of your application pool.

3) If the problem is happening during request processing of a particular request, you can try to make a different request to the site that does not cause the exception, and then attach the debugger by running the following from the command-line:

> windbg -g -p <PID>

Where <PID> is the PID of the IIS worker process you are debugging.  You can get it from Task Manager or by running tasklist /fi "imagename eq w3wp.exe".

If you have the debugger attached at this point, skip steps 4 and 5

4) If the problem is happening on every request, then you won't have a worker process running that you can attach to since it will go away as soon as you make a request.  In this case, you will need to attach a debugger immediately after the worker process is started, so that you can catch a startup exception before it tears down the process.

This is where startup debugging comes into play.  It is done by configuring the debugger to attach to the process as soon as its started, by setting the Image File Execution Options registry key from the command line:

> REG ADD "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\w3wp.exe" /v Debugger /d "c:\debuggers\ntsd.exe -server npipe:pipe=w3wp -g" /t REG_SZ /f

This creates a sub-key named "W3WP.EXE" in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options, and in that sub-key creates a String value named "Debugger" and set its value to "c:\debuggers\ntsd.exe -server npipe:pipe=w3wp -g".

For this to work, you have to make sure that the path to the debugger is correct.  If the debuggers are already in the path, you can omit the full path.

Enable the debugger to attach when the process starts with Image File Execution Options 

5) Now, lets attach.  

- Make the request that causes the crash 

This will trigger the IIS worker process to be started, and will automatically attach the debuger, breaking into the process before any IIS initialization takes place.

- Now, connect to the debugger from the command-line:

> windbg -remote npipe:server=localhost,pipe=w3wp

5) Inspect the exception stack trace

The debugger window should now be broken in at the location of the exception.  You can inspect it further by typing "k" and pressing Enter.

This should give you the full stack trace of the exception. 

If you are missing symbols, you can get them from the Microsoft's public symbol server.  To do that, type the following in the debugger:

> !sympath+ SRV*c:\symbols*http://msdl.microsoft.com/download/symbols
> .reload
> k

When you are done, be sure to disable the automatic debugging on start-up:

> REG DELETE "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\w3wp.exe" /v Debugger /f

Hope this helps you get to the bottom of particularly nasty start-up crashes.  If the exception stack is within IIS or a third party module, please post it on forums.iis.net so we can take a look.

Thanks,

Mike

Published 19 May 07 10:57 by Mike Volodarsky
Filed under: ,

Attachment(s): ImageFileExecutionOptions-Debugger.jpg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Mike Volodarsky's WebLog said on May 19, 2007 12:50 PM:

In a previous post titled Where did my IIS7 server go? Troubleshooting "service unavailable" errors ,

# iis said on May 19, 2007 1:00 PM:

In a previous post titled Where did my IIS7 server go? Troubleshooting "service unavailable" errors

# dratengon said on August 15, 2007 7:49 AM:
Hi! Mike, I am using vista business and VS2005 TS w sp1. I have installed IIS (click everything). I also install latest debugger from the link you provided. I got this problem 503. I hv tried both way easy 1 and this but unsuccessful. I cant any w3wp.exe and the debugger from my vista. Any idea?
# Mike Volodarsky said on August 15, 2007 9:29 PM:

dratengon,

I am not sure what the problem is from your post - are you saying you are unable to see the w3wp.exe worker process on your machine?

If so, then most likely there is a problem that is preventing the worker process from ever being started.  Please see my other post about troubleshooting these problems: http://mvolo.com/blogs/serverside/archive/2006/10/19/Where-did-my-IIS7-server-go_3F00_-Troubleshooting-_2200_service-unavailable_2200_-errors.aspx.

Thanks,

Mike

# Scolo said on September 4, 2007 9:22 PM:
I had that error and i wasn't able to solve it. I was getting crazy. Finally in Basic Configuration of the website i've changed Aplications Group to ASP .NET 1.1 and it works :) if it helps anyone :)
# Ken Payson said on October 9, 2007 1:12 AM:
Mike, I'm having trouble woth 503 Errors. I'm running IIS7 on vista premium. I get this error going to any page on localhost ex http://localhost/test1/hello.htm When I run \system32\inetsrv\appcmd start apppool DefaultAppPool, I get an error message that says WAS Service is not available - try starting the service first. I downloaded the debugging tools. The path is C:\Program Files\Debugging Tools for Windows\windbg.exe The REG ADD command gives an access denied error but I created a registry key using regedit in HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\w3wp.exe with value "C:\Program Files\Debugging Tools for Windows\windbg.exe" -server npipe:pipe=w3wp -g The debugger isn't being started when I try to go to a web site or when I try to start the appPool Don't know what to try. I've been fighting with this for a long time now. Any help would be great
# Mike Volodarsky said on October 13, 2007 1:02 PM:

Hi Ken,

In your case, the worker process isnt even being started because your application pool cannot be started, so this technique is not applicable.  

Try starting WAS first:

> net start was

If this fails, look in the "System" eventlog for errors indicating why WAS could not start.

Thanks,

Mike

# Francisco Rodriguez said on November 16, 2007 6:03 PM:
Mike, how are you ? We are experiencing the 1011 error (A process serving application pool 'AppPool' suffered a fatal communication error with the World Wide Web Publishing Service. ) and having our IIS crashed several times a week. We are running on W2003 and IIS 6.0. I've seen that yu have a procedure for IIS7.0, do you have one for IIS 6.0 ? Can you help me, please ? I started running the debug diagnostics but I really don't understand it. Thanks a lot.
# Mike Volodarsky said on December 8, 2007 1:55 PM:

Hi Francisco,

You can apply this technique to IIS6 as well to attach a debugger at the start of the worker process.  However, in your case it sounds like your crash does not happen at startup, so you can attach a debugger normally at any time and wait for a crash to occur.

Tools like DebugDiag can do this for you (monitor for a crash, and then attach a debugger).

Thanks,

Mike

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below


About Mike Volodarsky

For the past 5 years, I was the core Program Manager for Microsoft ASP.NET 2.0 and IIS 7.0 products. I drove the design and development of the IIS 7.0 web server core, the IIS FastCGI support, the AppCmd command line tool, the ASP.NET Integrated pipeline, and other special projects around server security, performance, and scalability. Now, I am working on my own on cutting edge web server tech on top of the Microsoft IIS platform, and continue blogging about it here.

About me



For the past 5 years, I was the core server Program Manager for the IIS 7.0 and ASP.NET 2.0 products at Microsoft.
Now, I work on advanced web server tech using IIS 7.0, .NET, and Windows Server 2008 and write about it in this blog.

View Michael Volodarsky's profile on LinkedIn

Writings



TechNet Magazine
>Top 10 Performance Improvements in IIS 7.0

MSDN Magazine
>IIS 7.0: Build Web Server Solutions with End-To-End Extensibility
>IIS 7.0: Enhance Your Apps with the Integrated ASP.NET Pipeline
>IIS 7.0: Explore The Web Server For Windows Vista And Beyond
>Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0
>Fast, Scalable, and Secure Session State Management for Your Web Applications


Tools and Modules

LeechGuard
IconHandler 2.0
DirectoryListing
HttpRedirection
IIS Auth for Wordpress
iisschema.exe
PortCheck.exe v2.0

Popular Posts

- ASP.NET 2.0 Breaking Changes on IIS 7.0
- Develop IIS7 modules and handlers with .NET
- Troubleshoot IIS7 errors like a pro
- Troubleshooting 503 / "service unavailable" errors
- Troubleshooting "server not found" errors
- Create IIS7 sites, applications, and virtual directories
- Run Ruby on Rails with IIS FastCGI
- VS Debugging of ASP.NET applications on Windows Vista
- Stop hot-linking with IIS and ASP.NET

Tags

Search

Go

This Blog

Archives

Good IIS Blogs

Disclaimer

These postings are provided as is with no warranties, and confer no rights. The views expressed in this blog are entirely my own.

Syndication