Skip to content

No way to differentiate between Dart VMs per device with mDNS #130623

Open

Description

@vashworth

Is there an existing issue for this?

Steps to reproduce

  1. Have 2 devices
  2. Run flutter app through Xcode on Device 1
  3. Run flutter attach in project directory, when it prompts you to select a device, pick Device 2

Note: There are other ways in which this can occur, but this is just an easy way to recreate

Actual results

You'll eventually get an error like

Waiting for a connection from Flutter on iPhone SE (3rd generation)...
Connecting to the VM Service is taking longer than expected...
Still attempting to connect to the VM Service...
If you do NOT see the Flutter application running, it might have crashed. The device logs (e.g. from adb or XCode)
might have more details.
If you do see the Flutter application running on the device, try re-running with --host-vmservice-port to use a
specific port known to be available.
Exception attempting to connect to the VM Service: SocketException: Connection refused (OS Error: Connection refused,
errno = 61), address = 127.0.0.1, port = 58122

Behind the scenes, it's using mDNS to find the Dart VM. It finds the Dart VM from device 1 and tries to connect to it using Device 2, which obviously doesn't work.

We should differentiate Dart VMs per device.

Logs

Logs
<!-- Paste your logs here -->

Flutter Doctor output

Doctor output
[!] Flutter (Channel [user-branch], 3.13.0-3.0.pre.32, on macOS 13.4.1 22F82 darwin-arm64, locale en)
    ! Flutter version 3.13.0-3.0.pre.32 on channel [user-branch] at xxx
      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/docs/get-started/install.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
    • Framework revision 8e80663640 (27 hours ago), 2023-07-13 10:50:24 -0700
    • Engine revision 88b8581516
    • Dart version 3.1.0 (build 3.1.0-307.0.dev)
    • DevTools version 2.25.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.

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at xxx
    • Platform android-33, build-tools 33.0.0
    • ANDROID_SDK_ROOT = xxx
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A5195m
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.1)
    • 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 11.0.15+0-b2043.56-8887301)

[✓] VS Code (version 1.80.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.68.0

[✓] Connected device (4 available)

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

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Jul 17, 2023
  2. huycozy commented on Jul 17, 2023

    @huycozy
    Member

    Hi @vashworth
    Are you seeing this issue with two physical devices?

    I checked this issue on a physical device and an emulator. But I received a different error message in stack trace as below. Is this another issue?

    [        ] Please choose one (or "q" to quit): 
    [+2237 ms] 2
    [  +59 ms] Waiting for a connection from Flutter on iPhone...
    [  +12 ms] Checking for advertised Dart VM Services...
    [ +168 ms] Checking for available port on com.example.testMdns._dartVmService._tcp.local
    [   +2 ms] Checking for authentication code for com.example.testMdns._dartVmService._tcp.local
    [+4862 ms] Attempting to forward device port 54540 to host port 54613
    [   +2 ms] executing: /Users/huynq/Documents/GitHub/flutter/bin/cache/artifacts/usbmuxd/iproxy 54613:54540 --udid
    d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e --debug
    [+1012 ms] Forwarded port ForwardedPort HOST:54613 to DEVICE:54540
    [  +44 ms] Connecting to service protocol: http://127.0.0.1:54613/tBCs9mjj4-w=/
    [  +23 ms] Fail to connect to service protocol: http://127.0.0.1:54613/tBCs9mjj4-w=/: HttpException: Connection closed before full
    header was received, uri = http://127.0.0.1:54613/tBCs9mjj4-w=/ws
    [   +1 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:54613/tBCs9mjj4-w=/
    [   +2 ms] Un-forwarding port ForwardedPort HOST:54613 to DEVICE:54540
    [  +34 ms] "flutter attach" took 15,587ms.
    [   +6 ms] 
               #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
               #1      AttachCommand._attachToDevice (package:flutter_tools/src/commands/attach.dart:485:11)
               <asynchronous suspension>
               #2      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #3      AttachCommand.runCommand (package:flutter_tools/src/commands/attach.dart:270:5)
               <asynchronous suspension>
               #4      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1336:27)
               <asynchronous suspension>
               #5      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
               <asynchronous suspension>
               #7      FlutterCommandRunner.runCommand.<anonymous closure>
    (package:flutter_tools/src/runner/flutter_command_runner.dart:296:9)
               <asynchronous suspension>
               #8      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #9      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:244:5)
               <asynchronous suspension>
               #10     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:91:9)
               <asynchronous suspension>
               #11     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
               <asynchronous suspension>
               #12     main (package:flutter_tools/executable.dart:91:3)
               <asynchronous suspension>
               
  3. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 17, 2023
  4. vashworth commented on Jul 17, 2023

    @vashworth
    ContributorAuthor

    @huycozy Yeah I used two physical devices. I would image it's probably the same problem if you use two simulator or one physical device and one simulator - it doesn't differentiate Dart VMs per device.

  5. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jul 17, 2023
  6. huycozy commented on Jul 18, 2023

    @huycozy
    Member

    I still can not attach when using one physical and one emulator device (I have only one physical device).

    But when I tried this again with two emulators, this time I got another issue:

    Please choose one (or "q" to quit): 3
    Waiting for a connection from Flutter on iPad Pro (9.7-inch)...
    There are multiple Dart VM Services available.
    Rerun this command with one of the following passed in as the app-id and device-vmservice-port:
    
      flutter attach --app-id "com.nevercode.triage (3)" --device-vmservice-port 63459
      flutter attach --app-id "com.nevercode.triage" --device-vmservice-port 63774
    
    

    Using the first suggested command will make attach work. This looks similar to a case mentioned at #122698 (comment). Labeling the issue to have more information.

  7. added
    platform-iosiOS applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    team-iosOwned by iOS platform team
    and removed
    in triagePresently being triaged by the triage team
    on Jul 18, 2023
  8. added
    team-toolOwned by Flutter Tool team
    and removed
    team-iosOwned by iOS platform team
    on Jul 24, 2023
  9. stuartmorgan-g commented on Jul 24, 2023

    @stuartmorgan-g
    Contributor

    Per offline discussion, while the repro case here is with iOS, the issue is with the selection/attach logic more generally.

  10. added
    P3Issues that are less important to the Flutter project
    triaged-toolTriaged by Flutter Tool team
    on Jul 25, 2023
  11. 1 remaining item

  12. added
    P1High-priority issues at the top of the work list
    on Jul 27, 2023
  13. removed their assignment
    on Nov 15, 2023
  14. flutter-triage-bot commented on Mar 20, 2024

    @flutter-triage-bot

    This issue is marked P1 but has had no recent status updates.

    The P1 label indicates high-priority issues that are at the top of the work list. This is the highest priority level a bug can have if it isn't affecting a top-tier customer or breaking the build. Bugs marked P1 are generally actively being worked on unless the assignee is dealing with a P0 bug (or another P1 bug). Issues at this level should be resolved in a matter of months and should have monthly updates on GitHub.

    Please consider where this bug really falls in our current priorities, and label it or assign it accordingly. This allows people to have a clearer picture of what work is actually planned. Thanks!

  15. vashworth commented on Mar 20, 2024

    @vashworth
    ContributorAuthor

    We were able to figure out a imperfect, but good enough workaround

    // If deviceName is set, only use records that match it
    if (deviceName != null && !deviceNameMatchesTargetName(deviceName, srvRecord.target)) {
    continue;
    }

    Deprioritizing.

  16. added
    P2Important issues not at the top of the work list
    and removed
    P1High-priority issues at the top of the work list
    on Mar 20, 2024
  17. added
    team-iosOwned by iOS platform team
    fyi-toolFor the attention of Flutter Tool team
    and removed
    team-toolOwned by Flutter Tool team
    on Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listplatform-iosiOS applications specificallyteam-iosOwned by iOS platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-iosTriaged by iOS platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions