C
C#2d ago
Ploxi

[Async Hell] Messed up Stacktrace

Before the call, i have the following stack trace: Image 1 After it, its shortened and scrambled up: Image 2 Thing is, i have a Adapter which does some retry logic and it seems like it gets messed up in there. https://gist.github.com/JKamsker/8379749b3736b4c95028e6022709b88f It enters the retry callback of "SendCollectionAsync" and after it, the stack is basically scrambled. Can i somehow preserve the stack? ConfigureAwait didnt help :/
Gist
Handler
Handler. GitHub Gist: instantly share code, notes, and snippets.
No description
No description
No description
4 Replies
many things
many things2d ago
Can i somehow preserve the stack?
why?
Ploxi
PloxiOP2d ago
I would expect the stacktrace to be 1:1 exactly the same when having executed a method. But in my case, it doesnt look like it @many things
Yawnder
Yawnder2d ago
@Ploxi Generally the stack trace is preserved. Where it gets less obvious is when the error happens in code that is deeper, but when it's encountered shallower in the stack. For example, if you have an exception in the Where clause of a Linq query, but you don't ToList() it, your stack trace will look like it's a bit out of nowhere since it didn't happen in the method where you added the clause, but where the call got resolved. Another case where the exception looks like it's missing things if when a task is moved around, and not awaited where you'd initially expect it.
Lex Li
Lex Li22h ago
Not very much changed after a decade, https://stackoverflow.com/questions/15410661/is-it-possible-to-get-a-good-stack-trace-with-net-async-methods Since not everyone is reading every call stacks, I don't think you see speedy improvements in the future, but both Microsoft and other IDE vendors have improved their debugging tools in this area, like https://devblogs.microsoft.com/visualstudio/new-debugging-and-profiling-features-in-visual-studio-v17-13/#display-unified-async-stacks-in-profiler

Did you find this page helpful?