【问题标题】:IIS Crash on stack overflow (unhandled) - Microsoft .NET 4.5 ASP.NET MVC 3堆栈溢出时 IIS 崩溃(未处理) - Microsoft .NET 4.5 ASP.NET MVC 3
【发布时间】:2013-06-19 11:03:21
【问题描述】:

我在 IIS 7 上的 ASP.NET MVC 3 应用程序有错误行为。我们在代码中存在堆栈溢出情况,它导致一般应用程序池崩溃没有正确的 System.StackOveflowException 抛出。因此,在开始执行有问题的函数后,w3wp.exe 因本机代码异常而崩溃

这是 HtmlHelper 扩展的代码(现已修复):

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);

    }

这是事件日志记录:

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

另一个:

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: 

我的问题:为什么在没有 StackOverflowException 的情况下会导致池崩溃?

【问题讨论】:

    标签: .net asp.net-mvc iis stack-overflow w3wp


    【解决方案1】:

    因为您会导致递归无限调用。

    Avatar 调用 UserAvatar,如果满足特定条件(例如,当您在磁盘上没有文件时)调用 Avatar。

    因此出现 StackOverflowException,这使得应用程序无法继续运行。这就是为什么你会得到一个原生异常(因为它是 CLR 正在崩溃。事件 0xc00000fd 是一个 StacokOverflowException)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 2011-06-24
      • 1970-01-01
      • 2010-11-14
      相关资源
      最近更新 更多