FirstChanceException and Threading.ThreadAbortException
I've learned a few things these last few days about exceptions,
debugging, and blowing up IIS 6. FirstChanceExceptions
(FCE) are
actually exceptions in a program that are passed to the attached debugger
before the application actually gets the exception - this allows you to
see what went wrong and where (well kind of - it can be very tricky).
Most FCEs are harmless since you'll only hear from them if you have a
debugger attached, and if your program is well written, it will catch the
exception, handle it, and continue in a graceful manner. If you receive a
SecondChanceException
(SCE) that means you screwed up, and now your
program crashed, which can either give a nice nasty "Unhandled Exception
at 0xblahblah" or give a pretty "Send this info to Microsoft" dialog box.
The reason behind the FCEs and SCEs in this post is the fact that at
random times throughout the day, my Application Pool in IIS6 will
randomly terminate (crash). As I have learned, trying to get a debug dump
can be difficult with IIS (since I don't have Visual Studio installed on
there). All the event logs tell me is that my pool suffered a fatal
exception during a heartbeat - lots of help right? Well, all is not lost
- I do know that when it blows sky high, I at least get the error
Connection_Abandoned_By_AppPool
- even more helpful! I ran across the
IIS Diagnostics Kit which includes the handy-dandy Debug Diagnostics
tool, which is where the FCE and SCE come in.
The best thing I can do at this point is, attach the Debug Diagnostics
tool to my IIS processes and hope the application will crash so I can get
a debug dump - the problem with that is the fact that it not only catches
SecondChanceExceptions, but also FirstChanceExceptions! This was causing
a problem because apparently my site was throwing a bunch of FCEs! After
a bit of research I discovered that calling any of the
Response.End()
, Response.Redirect()
, and Server.Transfer()
methods results in a System.Threading.ThreadAbortException
, an
exception I wasn't handling - which caused my server to create a useless
debug dump and hang the server while it did that. I have updated my code
as per KB312639
and either wrapped the code in try/catch blocks, or called the
CompleteRequest()
methods. With this new code, I hope to catch the
real problem of my site crashing and hope to fix it before I continue
working on this site.