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: