Thread.Abort in ASP.NET app causes w3wp.exe to crash

三世轮回 提交于 2019-11-30 07:15:44

I was able to reproduce the issue on Server 2008r2 with .NET 4.6 installed.

I suspect it was the same problem the rest of you are running into; ThreadAbortExceptions killing the application pool in the event log (though any unhandled exception would cause the issue in my case; but that may just be a global exception handler catching it and finishing with a Response.End or Redirect). The dump stacktrace also matches the one in Ian's answer.

There was a MS Connect ticket opened for the issue, and a recent KB hotfix resolves the issue for me.

Connect Article: https://connect.microsoft.com/VisualStudio/feedback/details/1605438/disabling-ryujit-breaks-asp-net

KB Hotfix: https://support.microsoft.com/en-us/kb/3098786

So far I have the only one solution:

    static class WebExtensions
    {
        public static void EndSafe(this HttpResponse response)
        {
            response.Flush();
            response.SuppressContent = true;
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

        public static void RedirectSafe(this HttpResponse response, string url)
        {
            response.Redirect(url, false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
    }

This is however forces me to ensure that there will be no code executed after it:

...some code
response.RedirectSafe(url);
return; //<-- important
...some more code

Pay attention, that only "return" is not enough in some cases (for example with recursive calls) and in some cases you may need to avoid using "return" (with try-finally constructions)

I ran into this exact same problem on Windows 8.1 today, after rebooting to install Windows Updates.

The problem was that I had manually disabled RyuJIT in the Registry, due to this issue, by adding the useLegacyJit DWORD and setting it to 1 (see Method #3). But one of the updates created the UseRyuJIT key in the same location and set it to 1 as well, and this apparently confused ASP.NET horribly.

The solution was to set useLegacyJit to 0 and issue an iisreset. After that, all is good in the world.

WinDbg's !clrstack showed the following frames when I debugged the w3wp.exe dump. Perhaps this will help others with the same error who are Googling for a solution:

000000ef9892be98 00007ffa0e2d1fea [HelperMethodFrame: 000000ef9892be98] 
000000ef9892bf80 00007ff99d776588 System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)
000000ef9892df90 00007ff9fc172345 [FaultingExceptionFrame: 000000ef9892df90] 
000000ef9892e490 00007ff99d7796c0 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest, System.Web.HttpContext)
000000ef9892e520 00007ff99d777377 System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)
000000ef9892e700 00007ff99d77655a System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)
000000ef9892e740 00007ff99d775c11 DomainNeutralILStubClass.IL_STUB_ReversePInvoke(Int64, Int64, Int64, Int32)
000000ef9892ef58 00007ff9fc100b4e [InlinedCallFrame: 000000ef9892ef58] System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef)
000000ef9892ef58 00007ff99d78cc1b [InlinedCallFrame: 000000ef9892ef58] System.Web.Hosting.UnsafeIISMethods.MgdIndicateCompletion(IntPtr, System.Web.RequestNotificationStatus ByRef)
000000ef9892ef30 00007ff99d78cc1b DomainNeutralILStubClass.IL_STUB_PInvoke
000000ef9892f000 00007ff99d77756c System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(IntPtr, IntPtr, IntPtr, Int32)
000000ef9892f1e0 00007ff99d77655a System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(IntPtr, IntPtr, IntPtr, Int32)
000000ef9892f220 00007ff99d775c11 DomainNeutralILStubClass.IL_STUB_ReversePInvoke(Int64, Int64, Int64, Int32)
000000ef9892f418 00007ff9fc100da3 [ContextTransitionFrame: 000000ef9892f418]

I've been experiencing the same issue on Win7 SP1. Web app compiled targeting .net 4.5.2 and running on .net 4.6. And I haven't been messing with the useLegacyJit or useRyuJIT registry flags.

Turned out "Enable 32-Bit applications" was unnecessarily set to Enabled on my app domain. Disabling it fixed the problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!