IIS Crash on stack overflow (unhandled) – Microsoft .NET 4.5 ASP.NET MVC 3-Collection of common programming errors
I have wrong behavior of ASP.NET MVC 3 application on IIS 7. We had stack overflow condition in code and it caused general application pool crash without correct System.StackOveflowException throwing. So, after starting of executing problematic function w3wp.exe goes down with native code exception.
Here is the code of HtmlHelper extension(now – fixed):
public static string Avatar( this UrlHelper helper, string fileName)
{
return helper.UserAvatar(fileName);
}
public static string UserAvatar( this UrlHelper helper, string fileName)
{
if (string.IsNullOrEmpty(fileName))
return EmptyPhotoImage(helper);
var photoPath = System.Web.Hosting.HostingEnvironment.MapPath(string.Format("~/Content/avatars/{0}", fileName));
if (!File.Exists(photoPath))
return EmptyPhotoImage(helper);
return Avatar(helper, fileName);
}
Here is the event log record:
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: ntdll.dll, version: 6.1.7601.17725, time stamp: 0x4ec4aa8e
Exception code: 0xc00000fd
Fault offset: 0x0000000000055d7f
Faulting process id: 0x1a6c
Faulting application start time: 0x01ce6c67c7179807
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: 0dd50093-d85b-11e2-9ee7-50e549e13906
Other one:
Fault bucket , type 0
Event Name: APPCRASH
Response: Not available
Cab Id: 0
Problem signature:
P1: w3wp.exe
P2: 7.5.7601.17514
P3: 4ce7afa2
P4: ntdll.dll
P5: 6.1.7601.17725
P6: 4ec4aa8e
P7: c00000fd
P8: 0000000000055d7f
P9:
P10:
My question: Why it causes pool crash without StackOverflowException?
-
Because you cause a recursive infinite invokation.
Avatar invokes UserAvatar which invokes Avatar if a certain condition is met, e.g when you have no file on disk.
Hence the StackOverflowException, which makes it impossible for the application to keep on running. Thats why you get a native exception (since it’s the CLR that is crasching. Event 0xc00000fd is a StacokOverflowException)