flutter / devtools

Performance tools for Flutter
https://flutter.dev/docs/development/tools/devtools/
BSD 3-Clause "New" or "Revised" License
1.58k stars 324 forks source link

Create a tool to track leaking async operations. #5581

Open kenzieschmoll opened 1 year ago

kenzieschmoll commented 1 year ago

Support a way to see all the pending Streams/Futures with a stacktraces. Original request: https://twitter.com/remi_rousselet/status/1641763619502280707.

rrousselGit commented 1 year ago

For reference, what triggered this tweet was me debugging a command line.

For some reason, even though the main of my command line had completed and all work had stopped, the program didn't actually end.

One workaround was to do the following:

void main() {
  try {
    await doSomething();
  } finally {
    exit(exitCode);
  }
}

But that's of course not ideal, and debugging it is non-trivial.

bkonyi commented 1 year ago

If you're having issues with your process not terminating after returning from main, you almost certainly have an open ReceivePort somewhere in your program. You can find out where this port was allocated with a description and stack trace under VM Tools -> Isolates -> Open Ports in DevTools (this requires the Enable VM developer mode to be enabled in the settings).

As for tracking async operations, I'm concerned that this will result in a large performance hit as collecting stack traces for each Future or Stream allocation is very expensive, especially considering how common it is to allocate these types. Any sort of async operation tracing will need some significant design work and likely need to be placed behind a flag.

jacob314 commented 1 year ago

Fyi @christopherfujino

christopherfujino commented 1 year ago

Fyi @christopherfujino

ahh yeah, thanks!

christopherfujino commented 1 year ago

Nice, this helped me get a stacktrace for a bug that had been bothering me for months (the test runner hanging when a tools test would fail).

kenzieschmoll commented 2 months ago

Perhaps this tool could be implemented by the community as a DevTools extension?