Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugger needs a way to show stacktraces for all waiting async calls #55561

Open
lukehutch opened this issue Apr 24, 2024 · 6 comments
Open

Debugger needs a way to show stacktraces for all waiting async calls #55561

lukehutch opened this issue Apr 24, 2024 · 6 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug vm-service The VM Service Protocol, both the specification and its implementation

Comments

@lukehutch
Copy link

lukehutch commented Apr 24, 2024

Sometimes my Flutter app gets stuck on the Android splash screen, and never starts up the Flutter router. I suspect this may be due to one of several async Dart calls, in the initialization of main, preventing the Flutter app from starting, (in other words, I suspect that one of them is awaited indefinitely). However, I have no way to determine exactly where the code is stuck, because when I click Pause (in VS Code), The debugger call stack sub-window says "Paused on pause", and then shows no stacktrace.

image

When I click Pause, I would expect to be able to see a list of all current async calls that are awaiting completion (similar to a list of running Threads, in a Java debugger), and I should be able to view the stacktraces of all of them, to determine which async call is holding up execution by not completing.

@devoncarew
Copy link
Member

I suspect this would need additional information in the vm service protocol to expose additional async machinery.

cc @bkonyi @DanTup

@devoncarew devoncarew added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. vm-service The VM Service Protocol, both the specification and its implementation labels Apr 25, 2024
@lukehutch
Copy link
Author

Just for context, to maximize concurrency, I frequently use await Future.wait(futuresList) with a list of numerous futures whose executions are not interdependent. Currently it's impossible to pause the debugger and see which of those futures have completed and which are still pending.

@lukehutch
Copy link
Author

PS what does "Paused on pause" actually indicate?

@DanTup
Copy link
Collaborator

DanTup commented Apr 25, 2024

@lukehutch do you have a code sample/steps that gets into this state? Is it a deadlock? I'm surprised there's nothing at all in the call stack - although I suspect if it did show something, it wouldn't be helpful to you.. If I understand correctly, what you really want is a list of all places that are suspended at an await (which seem a bit like threads, but are not threads since there may be many of them that are sharing a single thread).

@bkonyi does the VM Service expose anything like this?

I don't think we have anywhere to provide that information in DAP but it doesn't seem like this information would be useful only for Dart (JS/NodeJS are very similar), so it could be worth opening a discussion in the DAP repo about it (maybe just having a hierarchy for threads would work?).

PS what does "Paused on pause" actually indicate?

When things pause, we send a DAP StoppedEvent to VS Code with a reason:

reason: 'step' | 'breakpoint' | 'exception' | 'pause' | 'entry' | 'goto'
        | 'function breakpoint' | 'data breakpoint' | 'instruction breakpoint'
        | string;

VS Code seems to just prefix the reason with "Pause on", which looks reasonable for "Paused one exception" and "Paused on breakpoint" but looks a little odd when the reason is pause.


Edit: There is an issue about nested threads at microsoft/debug-adapter-protocol#339

@lukehutch
Copy link
Author

@lukehutch do you have a code sample/steps that gets into this state? Is it a deadlock? I'm surprised there's nothing at all in the call stack - although I suspect if it did show something, it wouldn't be helpful to you.. If I understand correctly, what you really want is a list of all places that are suspended at an await (which seem a bit like threads, but are not threads since there may be many of them that are sharing a single thread).

I haven't been able to get to the bottom of this yet, because of lack of debugger assistance, and the fact that the issue is sporadic.

What I see is that at least the Android part of my app will start up, because the Android splash screen is shown, but then my app never routes to the first page.

I am only assuming this is because of async code not completing, because I can't believe the Flutter Android app entry point would randomly fail to start Flutter. I have a bunch of async tasks that are run in parallel on app startup before routing takes place, and that is what I am attributing the cause to. I will post an update if I figure out what is happening.

However, separately from this specific issue that I am running into -- (and what this bug is really about) -- is the request that the debugger should be able to see all active async tasks, and their stacktraces. This is really critical to understanding a running program. I used the Java thread viewer in Eclipse many times to understand concurrent systems. In Java, you can pause individual threads separately, but in Dart/JS, you would pause the whole isolate.

@DanTup
Copy link
Collaborator

DanTup commented Apr 25, 2024

Thanks - I guess this would be something like the Tasks window in Visual Studio.

There are some related issues here:

I'm not sure we could make a great experience in VS Code without some DAP/VS Code support. I'd encourage adding 👍 's to those issues.

@a-siva a-siva added the type-enhancement A request for a change that isn't a bug label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-enhancement A request for a change that isn't a bug vm-service The VM Service Protocol, both the specification and its implementation
Projects
None yet
Development

No branches or pull requests

4 participants