Skip to content

"flutter attach" fails with "Failed to start DDS" if run before the app is up and running #169265

@DanTup

Description

@DanTup

Steps to reproduce

I'm trying to support auto-attaching the debugger to the emulator on Firebase Studio for a better experience. This involves running flutter attach for the emulator when the editor opens. However, we don't know if the app that Firebase Studio is launching is already up and running, so it's possible we will run the command while it's still launching.

flutter attach appears to wait for the app to start, however at the last moment it throws "Failed to start Dart
Development Service" instead of attaching. Attaching a few seconds later works fine.

To repro:

  • Open two terminal Windows in a Flutter project folder
  • Start an Android emulator
  • Run flutter run -d emulator in one terminal
  • While the app is building, run flutter attach -d emulator in the other terminal

Expected results

Flutter should attach to the device the same way it does if the command is run slightly later.

Actual results

The attach command will fail:

Waiting for a connection from Flutter on sdk gphone64 x86 64...
Error connecting to the service protocol: failed to connect to
http://127.0.0.1:55609/ERoNfHtDZ2E=/ DartDevelopmentServiceException: Failed to start Dart
Development Service

However running the command again succeeds.

Note: Sometimes the flutter run process actually throws the error, and the attach version succeeds and ends up connected!

Code sample

N/A, any Flutter app will do for testing.

Screenshots or Video

attach_fail.mp4

Logs

Logs
PS D:\Dev\Test Projects\flutter_counter> flutter --verbose attach -d emulator
[   +2 ms] Could not interpret results of "git describe": 3.33.0-1.0.pre.147
[  +44 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +20 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update.
[        ] Artifact Instance of 'GradleWrapper' is not required, skipping update.
[        ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[        ] Artifact Instance of 'LegacyCanvasKitRemover' is not required, skipping update.
[        ] Artifact Instance of 'FlutterSdk' is not required, skipping update.
[        ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'PubDependencies' is not required, skipping update.
[   +6 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe devices -l
[  +29 ms] List of devices attached
           emulator-5554          device product:sdk_gphone64_x86_64 model:sdk_gphone64_x86_64
           device:emu64x transport_id:2
[  +12 ms] C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell
getprop
[   +1 ms] Waiting for a connection from Flutter on sdk gphone64 x86 64...
[ +174 ms] VM Service URL on device: http://127.0.0.1:43769/7tmbv15pV7g=/
[   +1 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward tcp:0 tcp:43769
[  +24 ms] 51378
[        ] Forwarded host port 51378 to device port 43769 for VM Service
[   +2 ms] Connecting to service protocol: http://127.0.0.1:51378/7tmbv15pV7g=/
[  +21 ms] Fail to connect to service protocol: http://127.0.0.1:51378/7tmbv15pV7g=/:
HttpException: Connection closed before full header was received, uri =
http://127.0.0.1:51378/7tmbv15pV7g=/ws
[ +165 ms] VM Service URL on device: http://127.0.0.1:44821/qs32dbKNOJM=/
[        ] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward tcp:0 tcp:44821
[  +20 ms] 51384
[        ] Forwarded host port 51384 to device port 44821 for VM Service
[        ] Connecting to service protocol: http://127.0.0.1:51384/qs32dbKNOJM=/
[  +32 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to
VM service at http://127.0.0.1:51384/qs32dbKNOJM=/.
[ +185 ms] Warning: Failed to start DDS: Failed to start Dart Development Service
[        ] Fail to connect to service protocol: http://127.0.0.1:51384/qs32dbKNOJM=/:
DartDevelopmentServiceException: Failed to start Dart Development Service
[   +1 ms] Error connecting to the service protocol: failed to connect to
           http://127.0.0.1:51384/qs32dbKNOJM=/ DartDevelopmentServiceException: Failed to start
Dart
           Development Service
[   +1 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --list
[  +20 ms] Exit code 0 from: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --list
[        ] emulator-5554 tcp:51153 tcp:37775
           emulator-5554 tcp:51195 tcp:43769
           emulator-5554 tcp:51200 tcp:37775
           emulator-5554 tcp:51228 tcp:37943
           emulator-5554 tcp:51229 tcp:37943
           emulator-5554 tcp:51283 tcp:43769
           emulator-5554 tcp:51288 tcp:37943
           emulator-5554 tcp:51308 tcp:42891
           emulator-5554 tcp:51309 tcp:42891
           emulator-5554 tcp:51374 tcp:44821
           emulator-5554 tcp:51378 tcp:43769
           emulator-5554 tcp:51384 tcp:44821
[   +1 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51153
[  +19 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51195
[  +19 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51200
[  +20 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51228
[  +21 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51229
[  +20 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51283
[  +20 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51288
[  +21 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51308
[  +21 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51309
[  +21 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51374
[  +21 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51378
[  +20 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s
emulator-5554 forward --remove tcp:51384
[  +24 ms] "flutter attach" took 986ms.
[   +4 ms]
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:34:3)
           #1      AttachCommand._attachToDevice
(package:flutter_tools/src/commands/attach.dart:433:11)
           <asynchronous suspension>
           #2      AttachCommand.runCommand
(package:flutter_tools/src/commands/attach.dart:273:5)
           <asynchronous suspension>
           #3      FlutterCommand.run.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command.dart:1548:27)
           <asynchronous suspension>
           #4      AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #5      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
           <asynchronous suspension>
           #6      FlutterCommandRunner.runCommand.<anonymous closure>
           (package:flutter_tools/src/runner/flutter_command_runner.dart:501:9)
           <asynchronous suspension>
           #7      AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #8      FlutterCommandRunner.runCommand
           (package:flutter_tools/src/runner/flutter_command_runner.dart:438:5)
           <asynchronous suspension>
           #9      run.<anonymous closure>.<anonymous closure>
(package:flutter_tools/runner.dart:98:11)
           <asynchronous suspension>
           #10     AppContext.run.<anonymous closure>
(package:flutter_tools/src/base/context.dart:154:19)
           <asynchronous suspension>
           #11     main (package:flutter_tools/executable.dart:113:3)
           <asynchronous suspension>


[        ] Running 3 shutdown hooks
[   +1 ms] Shutdown hooks complete
[        ] exiting with code 2
PS D:\Dev\Test Projects\flutter_counter>

Flutter Doctor output

Doctor output
PS D:\Dev\Test Projects\flutter_counter> flutter doctor -v
[!] Flutter (Channel [user-branch], 3.33.0-1.0.pre.147, on Microsoft Windows [Version
    10.0.26100.3775], locale en-GB) [188ms]
    ! Flutter version 3.33.0-1.0.pre.147 on channel [user-branch] at
      D:\Dev\Google\Flutter\Flutter main
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at
      https://flutter.dev/setup.
    ! Warning: `dart` on your path resolves to D:\Tools\Dart\Stable\bin\dart.exe, which is not
      inside your current Flutter SDK checkout at D:\Dev\Google\Flutter\Flutter main. Consider
      adding D:\Dev\Google\Flutter\Flutter main\bin to the front of your path.
    ! Upstream repository git@github.com:DanTup/flutter.git is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to git@github.com:DanTup/flutter.git to dismiss
      this error.
    • Framework revision f5dbe6ff06 (25 hours ago), 2025-05-21 10:13:40 +0100
    • Engine revision 5458f42782
    • Dart version 3.9.0 (build 3.9.0-138.0.dev)
    • DevTools version 2.46.0
    • If those were intentional, you can disregard the above warnings; however it is recommended
      to use "git" directly to perform update checks and upgrades.

[✓] Windows Version (11 Pro 64-bit, 24H2, 2009) [1,338ms]

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3) [1,210ms]
    • Android SDK at C:\Users\danny\AppData\Local\Android\sdk
    • Emulator version 35.4.9.0 (build_id 13025442) (CL:N/A)
    • Platform android-36, build-tools 35.0.0-rc3
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13355223-b631.42)
    • All Android licenses accepted.

[✓] Chrome - develop for the web [55ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.5) [54ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35122.118
    • Windows 10 SDK version 10.0.26100.0

[✓] Android Studio (version 2024.3) [13ms]
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 21.0.6+-13355223-b631.42)

[✓] VS Code (version 1.100.2) [12ms]
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.111.20250501

[✓] VS Code (version 1.93.0-insider) [12ms]
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.105.20250203

[✓] Connected device (4 available) [229ms]
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 13 (API 33)
      (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [Version
      10.0.26100.3775]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome
      136.0.7103.114
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge
      136.0.3240.64

[✓] Network resources [492ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listfound in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool teamwaiting for customer responseThe Flutter team cannot make further progress on this issue until the original reporter responds

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions