We've recently transformed one of our visitors for an object tree-like structure (that is about 40 levels deep) to the async/await pattern because the innermost accept methods now perform work which uses async/await.
Everything works fine except when an exception is thrown deep in the call graph, then we run into StackOverflowExceptions.
Our current assumption: it looks like exception unwinding is happening on a single thread and we run into StackOverflowExceptions. This would explain the crashdump stack traces which have the exception throw statement on the call stack and then go up and up until we reach a StackOverflowException. (while during the normal flow only the async state machine and the current continuation is on the stack, for which there is enough stack space available)
Is using async/await reducing the possible stack "depth" in a default .NET application on .NET 4.7.2 to something smaller than 100? Is there a good way to overcome this? Is there a recommendation to not write async/await visitors in .NET? Is there another explaination for this behavior?
XmlReader.ReadAsync
method? – Anticosti