Dart-Code: Dart formatter Keeps running endlessly

Issue Type: Bug

It’s random. At times when you save dart code. Dart formatter starts running and do not stops for several minutes (around 5 minutes minimum). I have to cancel it and save again and same thing happens. Only solution is restart VScode or sometimes restart the PC.

Extension version: 3.21.1 VS Code version: Code 1.55.1 (08a217c4d27a02a5bcde898fd7981bda5b49391b, 2021-04-07T15:06:02.360Z) OS version: Windows_NT x64 10.0.19041

System Info
Item Value
CPUs Intel® Core™ i7-8550U CPU @ 1.80GHz (8 x 1992)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
protected_video_decode: enabled
rasterization: enabled
skia_renderer: enabled_on
video_decode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 7.89GB (1.46GB free)
Process Argv –crash-reporter-id fd9ee2dd-443c-41b6-b90c-1cb615a784b2
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstry244:30276681
pythonvsdeb440:30248342
pythonvsded773:30248341
pythonvspyt875:30259475
pythontb:30283811
openwsldoc:30282072
vspre833cf:30267465
pythonptprofiler:30281270
vshan820cf:30276953
pythondataviewer:30285071
vscus158:30286553

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 59
  • Comments: 89 (35 by maintainers)

Most upvoted comments

Flutter 2.2.2 has just been released to the stable channel which includes a fix for one of the issues mentioned above (where on macOS the analysis server would stop responding after certain types of files are modified).

Please upgrade to Flutter 2.2.2 and restart all instances of VS Code. If you’re still seeing this issue on Flutter 2.2.2 or later, please do let me know. Thanks!

I don’t know what is causing it, but all I see is “Saving ‘http.dart’: Running ‘Dart’ Formatter (configure)”. and it doesn’t stop. Started with the latest Flutter upgrade. Have to restart vscode everytime and try again, works for one or two saves. Is there anything I can provide to help solve this issue? Serious workflow problem.

Flutter 2.2.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision b22742018b (10 days ago) • 2021-05-14 19:12:57 -0700 Engine • revision a9d88a4d18 Tools • Dart 2.13.0

Screenshot 2021-05-25 at 15 24 53

happening to my and half my team on flutter 2.2 this is very frustrating. none of the fixes above worked.

I have deleted editor.codeActionsOnSave": null in settings.json and my problem fixed. null not acceptable.

@mellowcello77 a log could be very helpful:

  • Run the “Preferences: Open Workspace Settings” command from the VS Code command palette
  • Set the dart.analyzerInstrumentationLogFile to a file path for logging (either absolute, or relative like "logs/analyzer.txt" which will go in the project folder)
  • Reproduce the issue
  • Leave the “Saving…” notification up for a minute or so (on the off-chance it’s code that’s slow to format rather than the server not responding)
  • Take a copy of the log file
  • (you can then remove the log file setting)

The log file may contain parts of your source code so if it’s something you can’t share, please open the log file and look for the last few occurrences of :Res: near the bottom of the file which should show what request(s) the server last responded to. I’m interested to know what are the few requests (:Req) around that time that were not responded to.

If you can repro on a project without sensitive code, feel free to just attach (or email to me at logs@dartcode.org) the lines starting a handful above the last server response. Thanks!

@mellowcello77 got it - in that case I’m fairly sure it’s the same issue mentioned above. When you run a Flutter build if it modifies certain types of files (usually in the .dart_tool folder) the analyzer rebuilds some internal state that involves removing an old file watcher and adding a new one. That seems to cause an issue (I think a deadlock) that prevented the server from responding to any further requests.

If anyone sees this issue not on macOS or not after running a Flutter build/debug session and can provide a log, that would be useful. If it’s macOS after running a debug build, I think it’s probably covered by the existing fix.

I was facing the same issue and noticed it would only happen when my internet connection was slow or down. For me, disabling analytics solved the problem:

dart --disable-analytics

Having the same issues with the following -

Flutter 2.8.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision cf44000065 (6 days ago) • 2021-12-08 14:06:50 -0800 Engine • revision 40a99c5951 Tools • Dart 2.15.0

This helped me in VS Code:

Uninstall the Flutter extension and Dart extensions then reinstall them. Restart your VS Code

It seems to happen a lot less on Flutter 2.0.6. Temporary solution that worked for me:

  • Navigate your flutter folder;
  • Execute git checkout 2.0.6;
  • Execute flutter doctor to download binaries;
  • Go back to work.

@netgfx

Could it be that the formatting process requires some system resources to be available at the forefront (even if it doesn’t utilize them completely)?

I’m not certain, but I suspect it’s probably not the formatter here - I think the server is not responding correctly and then the format requests jut gets stuck (I think it was coincidence that I triggered something similar behaviour by actually having something that formatted slowly).

If this seems to happen after you’re just run a debug session and the analysis server appears to never recover, then it could be related to https://github.com/dart-lang/sdk/issues/45996 (which my or may not be specific to macOS), though I don’t fully understand what’s happening there yet.

@DanTup Restarting vscode fixed it. My log setting is active, I’ll repost from the next. I didn’t make any changes for dart.previewLsp in the initial setting. I think this event happens after this situation that run real ios device or simulator mixed.

I get this issue continuously on my Macbook Pro M1. Hovering over some code just shows loading... and does nothing. I have to cancel the dialog that just sits there in the bottom-right, quit, and restart the IDE. But it is getting worse.

Upgrading to flutter 2.2.2 did fix this for me on an M1 mac

@DanTup the error persisted to me, unfortunately.

For the record, the Dart formatter issue is fixed for me as of 2.2.2 (MacOS Big Sur 11.4 VS Code 1.57.0)

This comment: https://github.com/Dart-Code/Dart-Code/issues/3270#issuecomment-857349415

I uninstalled Flutter, Dart plugin in Visual Studio Code, and then restart IDE, it works magically! But just restarting the IDE does not help, you have to reinstall frameworks too!

Uninstall the Flutter extension and Dart extensions then reinstall them. Restart your VS Code

I suspect just restarting VS Code would have the same effect as doing this (and also just running the Reload Window command in VS Code), which is restarting the analysis server. Unfortunately I think it’s likely only a temporary solution.

For those that are seeing this issue, please do include your Flutter/Dart SDK versions and your OS in your comments, it’ll help understand if it’s an issue not seen before/fixed.

To summarise:

  • A few different issues (circular symlinks and unncessary analysis server context rebuilds) were fixed in Flutter 2.2
  • A macOS issue remains in Flutter 2.2 but has been fixed in master (dart-lang/sdk#45996) and there are requests open to cherry-pick to stable (dart-lang/sdk#46249 and dart-lang/sdk#46298).

So I’m particularly interested in any reports from this on Flutter 2.2 or later that are not macOS, or on latest Flutter master (or latest stable if/when those cherry-picks ship there) on any OS.

Unfortunately I’m having the same issue, but on macOS. Might just leave my SDK versions and OS here, maybe it’s helpful 😃 thx for investigating on that!

macOS 11.4

Flutter (Channel stable, 2.2.1, on macOS 11.4 20F71 darwin-x64, locale
    de-DE)
    • Flutter version 2.2.1 at /Users/patrick/Development/flutter
    • Framework revision 02c026b03c (13 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

@leidig54 if you can reproduce that, please file an additional bug. I tried but couldn’t repro, and I wouldn’t expect that to cause this sort of issue.

I’m still really interested in a log file of this happening (see my notes above - #3270 (comment)). I’ve not been able to reproduce this so seeing the requests that the server last responded to when this happened may help understand what’s going on. Thanks!

I spoke too soon - issue back again. I have captured it on the logs and emailed the file to you at the above email address.

It seems to take out my whole dart analyzer too. I lose all my automatic code completion and it also won’t detect warnings/errors in the VSCode problems tab.

Only occurs when I’m debugging on a physical device or emulator.

Doctor summary (to see all
details, run flutter doctor
-v):
[✓] Flutter (Channel
    stable, 2.2.1, on macOS
    11.3.1 20E241
    darwin-arm, locale
    en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.56.2)
[✓] Connected device (3 available)

• No issues found!

I have deleted editor.codeActionsOnSave": null in settings.json and my problem fixed. null not acceptable.

This fixed it for me. Having “null” raised a warning that an object was expected. Make sure to restart VSCode after.

even with no more than 300 lines of flutter code, no conditionals. But system overall low memory (less than 1Gb unallocated) still causes this issue on a daily basis. Could it be that the formatting process requires some system resources to be available at the forefront (even if it doesn’t utilize them completely)?