async/await and the visitor pattern [closed]
Asked Answered
H

0

4

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?

Hydrastinine answered 8/4, 2020 at 13:44 Comment(5)
Do you use the XmlReader.ReadAsync method?Anticosti
There appears to be a related question, in which the OP suggests they were not encountering this problem using .NET Core 3.1 - just something to try in your case, to see if the same behavior holds true... #61103736Publia
@TheodorZoulias: Sorry, the question was a bit confusing, we're not calling into XmlReader or something like that, we're parsing an object structure with the visitor design pattern. I've edited the question.Hydrastinine
Could you post a simplified example that demonstrates and reproduces your problem?Anticosti
I will discuss it further at #61103736 because it is exactly my problem.Hydrastinine

© 2022 - 2024 — McMap. All rights reserved.