Dart-Code icon indicating copy to clipboard operation
Dart-Code copied to clipboard

Stuck at "Connecting VM" when project filenames contain commas

Open readyiman opened this issue 2 years ago • 16 comments

Describe the bug After updating to Flutter 3.10.3, run (F5) from VsCode always stuck at Connecting VM. After a while run just stopped.

To Reproduce I'm not sure how to reproduce it, this happen on my main project which is quite large. I try with new project, it runs fine. I'm sure this likely either Flutter or Dart plugin on VsCode bug, because I tried all other run and it was fine.

I had successful run from:

  • VsCode run without debugging
  • Terminal flutter run
  • Android Studio run
  • Android Studio debug

Failed from:

  • VsCode run (F5) with plugin stable release
  • VsCode run (F5) with plugin pre release

Please complete the following information:

  • Operating System and version: WIN
  • VS Code version: 1.78.2
  • Dart extension version: 3.66.0
  • Dart/Flutter SDK version: 3.10.3
  • Target device (if the issue relates to Flutter debugging): Android Emulator API 31

readyiman avatar Jun 04 '23 02:06 readyiman

Does this happen in just this project, or also if you create a new project using the Flutter: New Project command?

Could you try capturing debugging logs while reproducing this (using the new project if it occurs there, so I can troubleshoot using the same code):

Thanks!

DanTup avatar Jun 04 '23 11:06 DanTup

Does this happen in just this project, or also if you create a new project using the Flutter: New Project command?

New projects works fine.

I had sent you the log via email.

readyiman avatar Jun 05 '23 00:06 readyiman

@readyiman could you post a screenshot of exactly where you're seeing "Connecting VM"? There's nothing obviously wrong in the log file that I can see, but it's also not clear to me exactly what you're seeing. Does the app ever load and is it just that there's a notification stuck on screen, or is it preventing the app from starting too?

DanTup avatar Jun 05 '23 10:06 DanTup

As a possible workaround to get you up and running, you can try adding this to your VS Code user settings:

"dart.previewSdkDaps": false,

This will switch back to the legacy debug adapters. However, we still need to track down the issue because those debug adapters will be dropped soon, so the issue will come back if we don't fix the new debug adapters.

Thanks!

DanTup avatar Jun 05 '23 10:06 DanTup

could you post a screenshot of exactly where you're seeing "Connecting VM"?

This is all the debug console log before run just stop:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
√  Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterGeolocator(11863): Attaching Geolocator to activity
D/FlutterGeolocator(11863): Creating service.
D/FlutterGeolocator(11863): Binding to location service.
D/FlutterGeolocator(11863): Geolocator foreground service connected
D/FlutterGeolocator(11863): Initializing Geolocator services
D/FlutterGeolocator(11863): Flutter engine connected. Connected engine count 1
Connecting to VM Service at ws://127.0.0.1:51107/pKIM0-XCOnA=/ws

Does the app ever load and is it just that there's a notification stuck on screen, or is it preventing the app from starting too?

The android screen just blank white. The app didn't force quit, it keeps running but nothing happen.

When running and If I set Dart: Open Dev Tools setting to flutter, Widget inspector will pop out and said

Main isolate is paused in the debugger

But when I press resume, the app did loaded!. Yet, the debugger is disconnected and run was over.

As a possible workaround to get you up and running, you can try adding this to your VS Code user settings:

"dart.previewSdkDaps": false,

This does work. App is loaded. This is the console log when it loaded:

Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
main.dart:1
√  Built build\app\outputs\flutter-apk\app-debug.apk.
D/FlutterGeolocator(12383): Attaching Geolocator to activity
D/FlutterGeolocator(12383): Creating service.
D/FlutterGeolocator(12383): Binding to location service.
D/FlutterGeolocator(12383): Geolocator foreground service connected
D/FlutterGeolocator(12383): Initializing Geolocator services
D/FlutterGeolocator(12383): Flutter engine connected. Connected engine count 1
Connecting to VM Service at ws://127.0.0.1:52482/NBu822ZsOOY=/ws
I/flutter (12383): elmlog Using Firebase Emulator: Auth, Firestore, Functions.
I/flutter (12383): elmlog package:elm/firebase/emulators/set_firebase_emulators.dart 16:3  setFirebaseEmulators
set_firebase_emulators.dart:16
I/flutter (12383): Mapping Auth Emulator host "localhost" to "10.0.2.2".
I/flutter (12383): Mapping Firestore Emulator host "localhost" to "10.0.2.2".
I/flutter (12383): Mapping Functions Emulator host "localhost" to "10.0.2.2".
I/flutter (12383): elmlog START

I notice there is main.dart:1 line difference there on start. elmlog is my custom logger.

Anyway, I choose to work with AS for now. App run works fine there. And I'm actually quite impressed with this Flamingo version, it feel fast. And the (new?) console logs, wow.

readyiman avatar Jun 05 '23 21:06 readyiman

Thanks for the info. I'm looking through the code again and think I may have found the issue (or at least an issue). When configuring the isolates, we ask the VM to resolve a bunch of package URIs into file URIs, using a request called "lookupResolvedPackageUris".

In your log, there are 1805 entries in the outgoing response, but there are 1806 in the response! We enumerate the response and try to access the URI from the request, so I think we might have an exception here (although I don't know why that wouldn't show up in your logs).

The top few and bottom few of the URIs seem to match up, so I'll have to compare the full set and see where they get out of sync to see whether I can find what might trigger it and reproduce it.

I presume you didn't modify the log file in a way that could've removed an item from the lookupResolvedPackageUris request/response?

DanTup avatar Jun 06 '23 17:06 DanTup

Ok, looks like one of the URIs in the request (map_card_ps.dart) didn't get mapped, and instead returned null. However there are two nulls in the list, which has shifted everything out.

Do you know if there's anything different about the file map_card_ps.dart compared to the others? I don't see any obvious reason why it would fail to map.

lookupResolvedPackageUris

@bkonyi this seems like a bug that lookupResolvedPackageUris is including more items in the result set than it should. It seems like it might be happening when something isn't mapped (two nulls are inserted instead of one). Do you know if this is possible (or could you point me to the implementation for me to see if I can understand it?)

Edit: Hmm, if this is the implementation, it doesn't seem like it could be adding extra values.

DanTup avatar Jun 06 '23 17:06 DanTup

I presume you didn't modify the log file in a way that could've removed an item from the lookupResolvedPackageUris request/response?

I only removing my key and part of my app name. No change for others. No change for directory and filename.

Do you know if there's anything different about the file map_card_ps.dart compared to the others? I don't see any obvious reason why it would fail to map.

File name is centered_map_card_ps.dart. I don't understand what you mean with difference. It look like any other file to me. The content is small. This is the whole content:

import 'package:flutter_riverpod/flutter_riverpod.dart';

class CenteredMapCardPs {
  static final showSharedBarP = StateProvider.autoDispose<bool>((ref) => false);
}

I wonder why I can debug without issue on AS with similar plugin. Is it not from same source? Note: I'm not actively using AS for long time, I did use VsCode for some years.

readyiman avatar Jun 06 '23 21:06 readyiman

File name is centered_map_card_ps.dart. I don't understand what you mean with difference. It look like any other file to me.

I'm not sure what we're looking for either, so any differences might be helpful. If you search for that filename, are the files that import it perhaps importing it in a different way to others? (for example, do some use import "package:... and some just import with relative paths?)

I wonder why I can debug without issue on AS with similar plugin. Is it not from same source?

VS Code (more more specifically the new debug adapters) are using some new APIs to map package: URIs back to file:/// URIs. This is needed so when you hit a breakpoint in package:foo/foo.dart we can tell VS Code which file on your disk it should jump to. The new APIs are much simpler than what VS Code did (and IntelliJ does) before, but for some reason it's not working right in this project of yours.

Anything you can do that might help me reproduce this would be appreciated. If you're able to trim down a copy of your project to something you can share but still reproduces the issue, that might help me debug. If there's anything about this project that might be significantly different to the sample project where this didn't happen, that might be relevant too (for example does it use plugins, or use multiple isolates? Anything that might explain why it only happens in this project might help me track it down).

Thanks!

DanTup avatar Jun 06 '23 22:06 DanTup

OMG @DanTup you won't believe this, but the cause for this is because there is COMMA , on the filename. There is comma before words map on centered_,map_card_ps.dart at my VsCode filename. Removing it (by renaming it) remove the issue.

I can easily reproduce this issue by making a file with comma on it's filename and import it.

Some notes:

  1. In your screenshot there's appear no comma on it, but you did give me incomplete filename.
  2. I didn't copy the filename when I write it on reply above, I just wrote it and I miss the comma.
  3. There is warning on VsCode for making name with comma, yet somehow I miss it. This file only the one that have comma.

readyiman avatar Jun 07 '23 02:06 readyiman

Oh another note: Somehow this bug? only happen on VsCode if run with debugger.

readyiman avatar Jun 07 '23 02:06 readyiman

I can easily reproduce this issue by making a file with comma on it's filename and import it.

Aha! Thanks for tracking this down. Hopefully this will help me reproduce and we can get if fixed :-)

Oh another note: Somehow this bug? only happen on VsCode if run with debugger.

When you run without debugger, we don't call these APIs (because we don't connect to the VM Service and don't need to translate paths).

DanTup avatar Jun 07 '23 09:06 DanTup

I was able to reproduce this and have opened https://github.com/dart-lang/sdk/issues/52632. I'll keep this issue open until it's fixed and as a placeholder to include the fix in release notes.

Thanks again for tracking this down - I realise now the reason I missed the comma when comparing the results, was that I had replaced " and , out of the JSON as I was pasting into Google Sheets, so it wasn't in my comparison. Doh!

DanTup avatar Jun 07 '23 09:06 DanTup

Btw @DanTup I wonder if this non valid filename can be added to Dart analysis (lint/warning)? Because single programmer with large files like me had slim chance to detect it, and it may affect other things in the future. Or maybe it is ok for Dart to have non valid filename because it is actually able to run it?

readyiman avatar Jun 07 '23 23:06 readyiman

@readyiman there is already a lint - file_names that would catch this:

image

But this filename isn't really invalid. It's not working because of a bug in the VM Service - once that's fixed, this issue should go away :-)

DanTup avatar Jun 08 '23 19:06 DanTup

I hade the same problem, And I found my solution, One of my file name had comma in it profile_edit_scree,.dart🤦🏻‍♂️, then I removed the comma everything is fine. For 20 days I was using the terminal for every update I clicked the terminal then I pressed "r" to refresh. To find the file in easy way if you have big project like me, with more than 100+ files. use regular expression use import (.*?,.*?)

SalarPro avatar Feb 20 '24 21:02 SalarPro

I'm tidying up the issue tracker and closing this issue because there's nothing to do here in Dart-Code. Once the SDK issue (https://github.com/dart-lang/sdk/issues/52632) is solved, commas in filenames will stop causing problems without any changes here.

DanTup avatar Aug 05 '25 10:08 DanTup