简体   繁体   English

异常代码 0xe0434352 崩溃 w3wp.exe | 点网运行

[英]Exception code 0xe0434352 that crashes w3wp.exe | dotnet run

I find out that an error on my server was crashing the server and not being handled by global exception handler.我发现我的服务器上的一个错误导致服务器崩溃并且没有被全局异常处理程序处理。 I am not totally sure that what I will describe is the same problem that I am having (using 3rd party libs, plus custom logic in the middle... is difficult to analyze the full code), although I suspect that is the same.我不完全确定我将描述的问题与我遇到的问题相同(使用 3rd 方库,加上中间的自定义逻辑......很难分析完整的代码),尽管我怀疑这是相同的。

  • Can anyone explain me why the global exception handler cannot handle exceptions raised after start writing the response?谁能解释一下为什么全局异常处理程序无法处理开始编写响应后引发的异常?
  • And if is something we can do about this?如果我们能做些什么呢?

I am using ASP.Net core 3.0我正在使用 ASP.Net 核心 3.0

public class Startup
{
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
        app.UseExceptionHandler(options => options.Run(HandleException));

        app.Map("/map1", HandleMapTest1);
        app.Map("/map2", HandleMapTest2);
    }

    private Task HandleException(HttpContext context) {
        try
        {
            var exceptionFeature = context.Features.Get<IExceptionHandlerPathFeature>();
            Console.WriteLine("Unhandled exception");
        }
        catch { /*ignore*/ }
        return Task.CompletedTask;
    }

    private static void HandleMapTest1(IApplicationBuilder app) {
        app.Run(async context =>
        {
            throw new System.Exception("It will be caught by HandleException");
            await context.Response.WriteAsync("Map Test 1");
        });
    }

    private static void HandleMapTest2(IApplicationBuilder app) {
        app.Run(async context =>
        {
            var x = new MyClass();
            x.DoDSomething();
        });
    }
}

class MyListener
{
    public void Check(Action<int> action) {
        action(1);
    }
}

class MyClass
{
    public MyListener DoDSomething() {
        var x = new MyListener();
        x.Check(EnterFieldNode);
        return x;

        async void EnterFieldNode(int num) => await Validate();
    }

    private async Task Validate() {
        // do something that explodes
        throw new Exception();
    }
}

I have found out this article , that uses the UnhandledException event from the AppDomain to catch the exception, although is not possible (at least in a straightforward way) to avoid the server crash.我发现这篇文章使用来自 AppDomain 的 UnhandledException 事件来捕获异常,尽管不可能(至少以直接的方式)避免服务器崩溃。


UPDATE 1: Example updated.更新 1:更新示例。 Finally was able to reproduce.终于可以复生了。 The code is the most similar possible to what is happening with a 3rd party library that I am using.该代码与我正在使用的第 3 方库所发生的情况最相似。 It crashes the w3p process and I got a error in event viewer with Exception code 0xe0434352.它使 w3p 进程崩溃,并且在事件查看器中出现错误,异常代码为 0xe0434352。

As @KirkLarkin mentioned above in the comments, the async void is the problem.正如上面评论中提到的@KirkLarkin, async void是问题所在。 Here's some links with more details:以下是一些包含更多详细信息的链接:

Async Guidance 异步指导

TaskScheduler.UnobservedTaskException Event TaskScheduler.UnobservedTaskException 事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM