• Elegant Code Cast


    View in iTunes Any Podcatcher

Tracking down an unhandled exception

Recently I was tracking down an unwanted error that has been recycling my application pool. One app pool recycling is one too many for me. The error details were useless, but a quick search put me on the right path. The error was the following.

EventType clr20r3, P1 w3wp.exe, P2 6.0.3790.1830, P3 42435be1, P4 mscorlib, P5 2.0.0.0, P6 4333ab80, P7 bd0, P8 59, P9 system.nullreferenceexception, P10 NIL.

Searching for an error this cryptic reassured me that I need to take measures to improve the details of my error handling. As a result, I immediately created two HttpHandlers to deal with unhandled exceptions such as this one, and one for more generic error handling. By logging more detailed information, I can better detect the error and fix it. This is nothing new, but definitely important. A good article on reporting unhandled exceptions can be found here, ASP.NET 2.0 Unhandled Exception Issues.

After implementing this solution, my error reared its ugly head again, and a detailed error log was recorded. Perfect! As I am reading the detailed error message and stack trace, I am finding myself even more confused. Nothing in the stack trace could be found in my code. After another internet search, I found one dedicated thread specifically for this error. The error details are below.

System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(Object state)
    at System.Threading._TimerCallback.TimerCallback_Context(Object state)
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading._TimerCallback.PerformTimerCallback(Object state)

   
Closing the chapter on this error, the only thread I found with details on this can be found here, Null Reference Exception in SessionStateModule. The fix turned out to be a Microsoft hotfix that I had to install on my servers that basically updated the aspnet_wp.exe, System.Web.dll, and webengine.dll. With the fix in place, so far so good - no signs of the error after three weeks of peak usage.

Lessons Learned

Errors that occur outside of the main application context will cause the application pool to be recycled in ASP.NET 2.0 by default. While this default can be disabled, it is a better approach to throw more detailed information about each error. Using the unhandled exception HttpModule will help isolate errors that originate on threads outside of the application’s context. When catching errors, provide as much detailed information as possible to give yourself a fighting chance.

kick it on DotNetKicks.com

One Response to “Tracking down an unhandled exception”

  1. That is nice because you can add that to an app after deploymnet. Good idea.

Leave a Reply

Close
E-mail It