最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Why is there a StackOverflowException with ConfigureAwait(false) in an ASP.NET app but not with ConfigureAwait(true)? - Sta

programmeradmin3浏览0评论

I have an ASP.NET app running on .NET 4.8. I am getting a StackOverflowException. I have an action method that calls another method CallBackMethod where using ConfigureAwait(false) in a statement that triggers a stack overflow exception. But the stack overflow exception occurs somewhere after completion of the task which affects this behaviour.

public static async Task CallBackMethod<T>() where T : Meta
{
    // Changing to ConfigureAwait(true) ensures no Stackoverflow exception
    var test = await asyncMethod1().ConfigureAwait(false);
    // Custom Exception is thrown from action.Invoke()
    await asyncMethod2().ConfigureAwait(false);
    test++;
}

For a specific scenario, a nested method deep within this asyncMethod2 call at line 2 throws a custom exception which is expected. But when it does that, my app throws stack overflow exception and exits.

If I change the first line in the method to

var test = await asyncMethod1().ConfigureAwait(true)

then the stack overflow exception is not thrown. Only the expected custom exception is thrown and handled.

I thought there could be some recursive call in my code but If I double the default stack size for my app then the stack overflow exception is not thrown.

I am not able to figure out what could be causing the stack overflow exception. I wanted to understand what is changing between ConfigureAwait(false) and true that the stack overflow exception is not being thrown.

Minimal repro example in this repo:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论