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

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

Closed
jointhejourney opened this issue Jan 7, 2024 · 21 comments
Closed

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

jointhejourney opened this issue Jan 7, 2024 · 21 comments
Labels
fixed in dart / flutter in debugger Relates to the debug adapter or process of launching a debug session is bug relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Milestone

Comments

@jointhejourney
Copy link

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
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

[✓] 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
Copy link
Member

DanTup commented Jan 10, 2024

@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!

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Jan 10, 2024
@mellowcello77
Copy link

mellowcello77 commented Jan 13, 2024

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
Copy link

mellowcello77 commented Jan 14, 2024

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
Copy link

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
Copy link
Member

DanTup commented Jan 15, 2024

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 (#4926 (comment)) 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
Copy link

@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.

breakpointvideo.mov

@DanTup
Copy link
Member

DanTup commented Jan 16, 2024

@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
Copy link

paulcardno commented Jan 17, 2024

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
Copy link

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
Copy link
Member

DanTup commented Jan 17, 2024

@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
Copy link
Member

DanTup commented Jan 17, 2024

@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
Copy link

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

@DanTup
Copy link
Member

DanTup commented Jan 17, 2024

@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 dart-lang/sdk#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
Copy link
Member

DanTup commented Jan 17, 2024

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

  • Your host OS (and if Mac, Intel or Apple CPU)
  • Your Flutter SDK version
  • The device you are running the app on (and if it's a physical device, please test if you can repro on a simulator, because that'll be easier for us to ensure we're testing the same thing)

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
Copy link

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
Copy link
Member

DanTup commented Jan 18, 2024

@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
Copy link
Member

DanTup commented Jan 18, 2024

@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 dart-lang/sdk#54650 (comment)

@DanTup DanTup added upstream in dart / flutter Needs changing in Dart or Flutter and removed awaiting info Requires more information from the customer to progress labels Jan 18, 2024
@DanTup DanTup added this to the v3.82.0 milestone Jan 18, 2024
@DanTup DanTup added the in debugger Relates to the debug adapter or process of launching a debug session label Jan 18, 2024
@QCIPaulCardno
Copy link

@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
Copy link
Member

DanTup commented Jan 18, 2024

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

@DanTup DanTup removed the upstream in dart / flutter Needs changing in Dart or Flutter label Jan 23, 2024
@DanTup
Copy link
Member

DanTup commented Jan 23, 2024

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

@DanTup DanTup closed this as completed Jan 23, 2024
@DanTup DanTup added relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available fixed in dart / flutter labels Jan 23, 2024
@DanTup
Copy link
Member

DanTup commented Jan 25, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in dart / flutter in debugger Relates to the debug adapter or process of launching a debug session is bug relies on sdk changes Something that requires changes in the Dart/Flutter SDK to ship before it will become available
Projects
None yet
Development

No branches or pull requests

5 participants