Dart-Code / Dart-Code

Dart and Flutter support for VS Code
https://dartcode.org/
MIT License
1.49k stars 303 forks source link

Flutter app freezes after adding a breakpoint in VS Code #4926

Closed jointhejourney closed 8 months ago

jointhejourney commented 9 months ago

Describe the bug Running an iOS or MacOS app from VSCode, as soon as I add a breakpoint the app freezes immediately. Not hot reload or hot restart is able to revive the app. Only stopping and starting again works.

To Reproduce Steps to reproduce the behavior:

  1. Start debugging an iOS or MacOS Flutter app
  2. On VS Code, add a breakpoint at any line in your code
  3. App will freeze

Unfortunately I have noticed some intermittent behavior, but I'd say 90% of the times it freezes.

Expected behavior App should not freeze.

Screenshots If applicable, add screenshots to help explain your problem.

Please complete the following information:

You can run the Dart: Collect Diagnostic Information command from the VS Code command palette (F1) to easily capture this information or provide it manually.

Workspace Environment ```text Dart Code extension: 3.80.0 Flutter extension: 3.80.0 (activated) App: Visual Studio Code App Host: desktop Version: mac 1.85.1 Workspace type: Dart, Flutter (LSP) Dart (3.2.3): /Users/user/Development/flutter/bin/cache/dart-sdk Flutter (3.16.5): /Users/user/Development/flutter (iPhone 15 (ios/ios)) ```
Output from 'dart info' `/Users/user/Development/flutter/bin/cache/dart-sdk/bin/dart info` If providing this information as part of reporting a bug, please review the information below to ensure it only contains things you're comfortable posting publicly. #### General info - Dart 3.2.3 (stable) (Tue Dec 5 17:58:33 2023 +0000) on "macos_arm64" - on macos / Version 13.5.2 (Build 22G91) - locale is en-US #### Project info - sdk constraint: '>=3.0.0 <4.0.0' - dependencies: collection - dev_dependencies: build_runner - elided dependencies: 4 #### Process info | Memory | CPU | Elapsed time | Command line | | -----: | ---: | -----------: | ------------------------------------------------------------------------------------------ | | 10 MB | 0.0% | 21:53:49 | dart devtools --machine --allow-embedding | | 448 MB | 0.0% | 21:53:49 | dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.80.0 | | 6 MB | 0.0% | 18:05:18 | dart run build_runner watch --delete-conflicting-outputs | | 29 MB | 0.0% | 21:53:49 | flutter_tools.snapshot daemon | | 105 MB | 0.0% | 04:04 | flutter_tools.snapshot debug_adapter | | 158 MB | 2.1% | 04:04 | flutter_tools.snapshot run --machine --start-paused -d 00008130-000C75382E08001C --devtools-server-address http:/ --target /main.dart --device-timeout 10 | | 509 MB | 0.0% | 03:50 | frontend_server.dart.snapshot --sdk-root / --incremental --target=flutter --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true -DFLUTTER_WEB_CANVASKIT_URL=https:/ --output-dill /app.dill --packages /package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/dd704641fca0f13458e044aee43be5d8.cache.dill.track.dill --source file:/dart_plugin_registrant.dart --source package:flutter/dart_plugin_registrant.dart -Dflutter.dart_plugin_registrant=file:/dart_plugin_registrant.dart --verbosity=error --enable-experiment=alternative-invalidation-strategy |
Output from 'flutter doctor' `/Users/user/Development/flutter/bin/flutter doctor -v` ```text [✓] Flutter (Channel stable, 3.16.5, on macOS 13.5.2 22G91 darwin-arm64, locale en-US) • Flutter version 3.16.5 on channel stable at /Users/user/Development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 78666c8dc5 (3 weeks ago), 2023-12-19 16:14:14 -0800 • Engine revision 3f3e560236 • Dart version 3.2.3 • DevTools version 2.28.4 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/user/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.13.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2022.2) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694) [✓] VS Code (version 1.85.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.80.0 [✓] Network resources • All expected network resources are available. • No issues found! ```
DanTup commented 8 months ago

@jointhejourney does this reproduce with a newly created app (using flutter create or the Flutter: New Project command)?

Can you describe exactly what you mean by the app freezing - do you mean you cannot interact with it on the device at all (it's just stuck on the last rendered frame)? Can you provide a screenshot of the whole VS Code window with both the Debug sidebar and the Debug Console visible?

Thanks!

mellowcello77 commented 8 months ago

This happens with me, over the last month, on all my projects.

As soon as I add a break point it freezes and I cannot interact with the programme I am debugging at all and have to stop and re run it. No error, no indication of what is causing it, just freezes. Causing serious delays on my projects freezing on every breakpoint.

What can I do to help?

Flutter 3.16.7 • channel stable • https://github.com/flutter/flutter.git Framework • revision ef1af02aea (3 days ago) • 2024-01-11 15:19:26 -0600 Engine • revision 4a585b7929 Tools • Dart 3.2.4 • DevTools 2.28.5 Visual Studio Code Version: 1.85.1 (Universal)

mellowcello77 commented 8 months ago

I just tested on May 2023 VS Code Version: 1.79.2, but same result. Add a break point = Flutter freeze instantly on my MacOS project, expecting same on iOS. Using an M2.

mellowcello77 commented 8 months ago

Are any of you guys using the Supabase package? I have this in common between my projects that are freezing. If not, let me know so I can count it out please.

DanTup commented 8 months ago

What can I do to help?

The most useful thing would be to help me get a repro so I can trigger this locally. Sharing a small (but complete) project that definitely triggers the issue and exact instructions I can follow would help.

I also had some questions above (https://github.com/Dart-Code/Dart-Code/issues/4926#issuecomment-1885161713) that would help (in particular, confirmation of whether it happens in a brand new project with no other changes, and a full screenshot of VS Code with the Debug Console and Debug side bar visible when this happens).

mellowcello77 commented 8 months ago

@DanTup Here is a video of what it does - I could not reproduce on a simple Flutter starter app.

On adding of the third break point you will see it freezing. The behaviour is random. Sometimes it freezes on the first one added. Please let me know what else I can do to help. Thank you for looking into this, my projects are standing still at the moment.

https://github.com/Dart-Code/Dart-Code/assets/60788896/96b54b8a-c827-4460-8a24-cd72cac39764

DanTup commented 8 months ago

@mellowcello77 if it's not happening in a new project, the most helpful thing would be to figure out the difference between a new project and your own that is triggering this. If it doesn't occur in the new project there may be something specific in your project that triggers it, and that might make it very difficult for me to reproduce.

In the meantime, a debugging log might help - although note that it may contain parts of your source code:

If you're not sure you can remove anything sensitive from the logs, try to stop logging quite quickly after the freeze occurs and then maybe just the last few lines of the log will contain the useful information.

paulcardno commented 8 months ago

This is also happening to me but I am unclear as to if its the same issue. But I can switch it on and off, that is make the freezing happen and stop it from happening. It relates to the creation of isolates. In my app, when it starts, I create 6 isolates. If I do this and then when the app stops at a breakpoint and I add or remove a breakpoint the app freezes. If I don't have the isolates running then all is good. I did just make a simple app with an isolate created in it but that worked. I am also using the BLoC code, so this could be interacting with it. @DanTup I can dig a little deeper if that would be helpful. I think it sounds like the same issue but if its not no point in working on this. I have a work around (not nice, but...) note - I just spent some time isolating the issue. Found it in my code, simplified things, testing as I went and then when I deleted all the units and folders not involved in the simplified code things are working better. Not 100% of the time and I cannot see why. Will have another look tomorrow.

mellowcello77 commented 8 months ago

Hi @DanTup, I have sent the log to logs@dartcode.org I hope the log shows something we can use, I indicated where I think it happens in the mail.

DanTup commented 8 months ago

@mellowcello77 thanks for the log! The last line in the log you sent starts like this:

[11:31:01] [DAP] [Info] ==> {"command":"setBreakpoints","arguments":{"source":{"

Was this the very last line captured, or was there anything after this? If that's the last thing, is it possible you could repeat the logging, but start capturing logs before launching the application? Currently we only log the VM Service traffic is logging begins at the start and it doesn't look like this one includes it.

In particular, I'm interested in whether anything logs after the setBreakpoints line when the freeze happens.

And finally, after capturing the logs above could you try adding the following to your VS Code settings (temporarily) and see whether the issue also occurs with it set?

"dart.previewSdkDaps": false,

This will force you back on to the legacy debug adapters. If the issue doesn't occur there, it might also help pinpoint where the issue lies.

Thanks!

DanTup commented 8 months ago

@paulcardno

Sorry, almost missed your comment above.

It relates to the creation of isolates. In my app, when it starts, I create 6 isolates. If I do this and then when the app stops at a breakpoint and I add or remove a breakpoint the app freezes. If I don't have the isolates running then all is good.

This is useful information. I would definitely appreciate if you're able to make a repro that can be shared. It's very difficult to debug issues like this remotely that occur on projects I don't have, but if you can help me reproduce it locally here it will be much easier for me to get to the bottom of.

mellowcello77 commented 8 months ago

@DanTup New log just sent. Added "dart.previewSdkDaps": false, but same result.

DanTup commented 8 months ago

@mellowcello77 thanks for the updated log and testing the legacy debug adapter! The log shows much the same - it seems like the VM never responds to the request to add breakpoints.

I feel like this is either a VM issue or a Flutter issue. I've opened https://github.com/dart-lang/sdk/issues/54650 with the important details from this thread.

I'll try again to repro this, but if anyone is able to trigger this in a shareable project that would certainly help too - please post on the SDK issue linked above with details if you can.

Thanks!

DanTup commented 8 months ago

Oh also, can anyone that's having this issue confirm:

It's not clear if any of those things are related, but it might help identify a pattern (or at least, allow us to try to repro in an environment that more closely matches yours).

Thanks!

QCIPaulCardno commented 8 months ago

I can reproduce this issue. Please find attached a screen shot of the break points and also link to repo that has the code for this.

Background information 1) Host MacOS 14.2.1 (23C71) 2) Flutter (Channel stable, 3.16.3, on macOS 14.2.1 23C71 darwin-arm64, locale en-NZ) 3) Running MacOS

notes 1) It seems that will less code or maybe less breakpoints its harder to reproduce. That is when I had all my code (and associated break points not sure the number) and I made this simple test it only required toggling the break point once, but when I removed all the other code (that was not longer needed) then it required many toggles (see below for details on how to reproduce this)

How to reproduce 1) See the attached image for the default number of break points and there position 2) run the app, when it break points at line 12 initialSetup(); press play. When it break points at line 15 print("first breakpoint - on "); toggle a breakpoint on line 16 'print( "second breakpoint...' on/off at least 20 times and fast. Press play. First press of play won't do anything, second press of play the app freezes.Screenshot 2024-01-18 at 3 30 13 PM 3) if you comment out line 12 initialSetup() and do the whole process again then it works.

@DanTup hopefully you can reproduce this. And the above it clear enough.

here is the repo https://github.com/QCIPaulCardno/freezing_breakpoint_issue_20240118/tree/main

DanTup commented 8 months ago

@QCIPaulCardno thanks! Unfortunately I haven't had any luck reproducing this yet (although I'm on an Intel mac... I'll try and test on an M1 Mac soon).

That said - it's not obvious to me how to tell if the app has frozen because it seems to only render a yellow screen - how are you telling when it's frozen? Do you also know if the spawned isolate freezes (eg.if you put a while (true) loop around the print and a small await delay, does the isolate continue printing?).

DanTup commented 8 months ago

@QCIPaulCardno I was able to construct a reliable repro by copying what you did and making some tweaks so I can see the app updating. I've posted the details over at https://github.com/dart-lang/sdk/issues/54650#issuecomment-1898302185

QCIPaulCardno commented 8 months ago

@DanTup fab that you can reproduce it. Just for completeness, when you breakpoint on line 15 and then do the toggling of line 16, and then press play twice you never get to line 18 breakpoint.

let me know if you need anything else.

DanTup commented 8 months ago

@QCIPaulCardno seems like the issue is understood now (see https://github.com/dart-lang/sdk/issues/54650#issuecomment-1898988501). Thank you for your help with getting to a repro :-)

DanTup commented 8 months ago

This issue has been fixed via https://github.com/dart-lang/sdk/issues/54650 and there are hotfix requests open at https://github.com/dart-lang/sdk/issues/54699 so the fix will hopefully turn up in a stable release in the near future.

DanTup commented 8 months ago

Looks like the fix has made it to the Flutter stable channel. Please run flutter upgrade and ensure you get 3.16.9 and let me know if you're still seeing the issue.

BullsEye34 commented 3 months ago

This issue has started occurring again on latest stable (3.22.1). Host: M1 Pro Ram: 16GB

Apparently, happens with Android Studio as well?

DanTup commented 3 months ago

@BullsEye34 I'm not able to reproduce this using my previous repro from https://github.com/dart-lang/sdk/issues/54650#issuecomment-1898302185. It may be a different issue with the same symptoms.

Could you file a new issue with more details about what you're seeing and how you're triggering it? A screen recording and a log file (see https://github.com/Dart-Code/Dart-Code/issues/4926#issuecomment-1893483966) would be very helpful. Thanks!

ebrahimmansur commented 2 weeks ago

I'm having the same issues host: thinkpad ram: 16GB Flutter 3.24.0 • channel stable Tools • Dart 3.5.0 • DevTools 2.37.2

as soon i add a break point it just freezes and the restart icon button disabled

DanTup commented 2 weeks ago

@ebrahimmansur please file a new issue with steps to repro and if possible a screen recording and log as noted in the comment above. Thanks!