Debug Diag | Troubleshooting IIS Applications – StackOverflowException

This is the first article in the series of the articles I have planned to write on Debug Diag tool. I am focusing purely on the troubleshooting and diagnosing of the StackOverflowException in IIS Application in this article.

It is very easy for us to diagnose an issue in local debug environment. It is even easier in testing environments. But it is a different scenario altogether, when we have issues in PROD environment. Custom logging helps to investigate most of the issues in PROD, but there are scenarios where our logging fails us and this is where Debug Diag helps us.

You can download Debug Diag here.

I have created a sample MVC application and hosted it on IIS on the Server. Inside the HomeController, I have created a method that calls itself recursively infinite times.

Recursive Method

Now when try to access the deployed website, after performing some operations website fails to load and on hitting URL again following error comes up.

Website Unavailable

This happens because Web Application Pool is stopped.

App Pool Stopped

This happens because of the “Rapid-Fail Protection” setting of Application Pool that shuts down application pool after set number of failures/crashes.

App Pool Advance Settings

Now if we check the Event Log, we see series of warnings and errors:

Event Viewer System

Warning states that Application Pool suffered some error.

Event Log Warning

After 5 warnings of about errors, Application Pool is disabled with following error in Event Log.

App Pool Disabled

There is one information and error in Application section of Event Log, which gives us more detail about the issue.

Event Viewer Application

Error shows, that process w3wp.exe crashed with “Exception Code: 0xc00000fd”, which means StackOverflowException.

Application Error

Information log, actually shows that it was StackOverflowException and some more details about Process/Application.

Windows Error

As you can see, there is not much information available on where the application is falling over, so to get more details I setup Debug Diag to catch the exception of type StackOverflowException on the server.

Open “DebugDiag 2 Collection” and on “Select Rule Type” screen, select option “Crash” and click Next.

Debug Diag 2 Collection

On “Select Target Type” screen, select option “A specific IIS web application pool” and click Next.

Debug Diag - Target Type

On “Select Target” screen, select the “Web Application Pool” you have deployed website on and click Next.

select app pool

On “Advance Configuration” screen, click on button “Exceptions” under “Advanced Settings”.

Advance configuration

On “First Chance Exception Configuration” screen, click on button “Add Exception”.

first chance of exception config

From the list of Exceptions on left side, select “C00000FD – Stack Overflow”. Select “Action Type” as “Full User Dump” and “Action Limit”, just leave it default.

Configure exception

exception added

Click on “Save & Close” and click “Next”.
On the next screen, give the rule name and dump location of your choice and click Next.

rule name

Keep default selection of “Activate the rule now” and click on “Finish”.

Rule Completed

Here the configuration of Debug Diag is done.

rule activated

Now we again try to reproduce the issue and we get the same error as above.

However, we are interested in the Debug Diag dump generated at the log folder we setup earlier. Here are the dumps generated: (5 dump file are generated as exception was caused 5 times before Application Pool was disabled).

Debug Diag Dumps

“xx__Log.txt” and “xx__ProcessList.txt” are of not much use here, our to go file is .dmp file.

You can open dump file with either with Debug Diag tool DebugDiag.Analysis or with Visual Studio. We will see how dump file is useful when opened with Visual Studio later in this post.

Open With

When you open dump file with DebugDiag.Analysis, system does some sort of processing and presents you the report in Internet Explorer.

Debug Diag Report

The report Analysis Summary section clearly shows, that StockOverflowException was caused at “WebApplication.Controllers.HomeController.GoToInfiniteLoop()”. Can’t get any simpler than this. 🙂

Plus, if one wants to take a look at the Stack Trace, click on thread number (31 in my example) at the end of error summary.

Stack Trace

However, here comes the interesting part, we can open dump file with Visual Studio and also debug the application if source code is available on your machine. For this to work, source code should be same as the deployed application.

Dump via Visual Studio

Action links on the right top corner helps you to debug your code. I selected Debug with Managed Only and here is the output. The Visual Studio breaks directly on the line of code where error occurs and we found the culprit.

Debug via Visual Studio

Same way you can configure multiple type of exceptions:

Multiple exceptions

You can also create the dumps for any unconfigured exception that may occur in your application. Set the respective values in “Unconfigured First Chance Exceptions”.

Unconfigured Exception

I will definitely keep on sharing more articles on Debug Diag, as I understand it better.