Skip to content

"flutter attach" fails to connect when using --debug-url #110260

Open

Description

@DanTup

If I run a Flutter app with flutter run:

danny@Dannys-MacBook-Pro src % flutter run         
// ...
An Observatory debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:55772/yRmpm6wAk9w=/
The Flutter DevTools debugger and profiler on Android SDK built for x86 is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:55772/yRmpm6wAk9w=/

And then try to connect to it using flutter attach with --debug-url, it fails:

danny@Dannys-MacBook-Pro src % flutter attach -d emulator-5554 --debug-url http://127.0.0.1:55772/yRmpm6wAk9w=/
Error connecting to the service protocol: failed to connect to http://127.0.0.1:55918/yRmpm6wAk9w=/

(note the port number in the error is different to the one I provided)

Connecting using the device (-d) seems to work fine.

Passing --debug-url is a workflow supported in VS Code to allow users to attach to Flutter apps that might have been launched externally from VS Code, but currently this fails for the reasons above.

I believe this used to work at some point in the past, because #70847 looks like a fix for a very similar issue, however even if I pass --no-dds to both flutter run and flutter attach here, I see the same failure.

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Aug 25, 2022
  2. exaby73 commented on Aug 25, 2022

    @exaby73
    Member

    Hello @DanTup. Thank you for filling this issue. I can reproduce this issue with the default counter app.

    Reproducible on:

    • Stable (3.0.5)
    • Beta (3.3.0-0.5.pre)
    • Master (3.1.0-0.0.pre.2481)

    Commands run

    > flutter run
    
    An Observatory debugger and profiler on sdk gphone64 x86 64 is available at: http://127.0.0.1:65415/yqkdOMccHd4=/
    The Flutter DevTools debugger and profiler on sdk gphone64 x86 64 is available at: http://127.0.0.1:9101?uri=http://127.0.0.1:65415/yqkdOMccHd4=/
    
    > flutter attach --debug-url "http://127.0.0.1:65415/yqkdOMccHd4=/"
    
    Error connecting to the service protocol: failed to connect to http://127.0.0.1:65476/yqkdOMccHd4=/
    

    Doctor Output

    flutter doctor -v (Stable)
    [✓] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.22000.856], locale en-IN)
        • Flutter version 3.0.5 at C:\Users\Nabeel\fvm\versions\stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision f1875d570e (6 weeks ago), 2022-07-13 11:24:16 -0700
        • Engine revision e85ea0e79c
        • Dart version 2.17.6
        • DevTools version 2.12.2
    
    [✗] Android toolchain - develop for Android devices
        ✗ Unable to locate Android SDK.
          Install Android Studio from: https://developer.android.com/studio/index.html
          On first launch it will assist you in installing the Android SDK components.
          (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
          If the Android SDK has been installed to a custom location, please use
          `flutter config --android-sdk` to update to that location.
    
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.2.32630.192
        • Windows 10 SDK version 10.0.19041.0
    
    [!] Android Studio (not installed)
        • Android Studio not found; download from https://developer.android.com/studio/index.html
          (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
    
    [✓] VS Code (version 1.70.2)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension can be installed from:
          🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    
    [✓] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.856]
        • Chrome (web)      • chrome  • web-javascript • unknown
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 104.0.1293.63
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 2 categories.
    
    flutter doctor -v (Master)
    [✓] Flutter (Channel master, 3.1.0-0.0.pre.2481, on Microsoft Windows [Version 10.0.22000.856], locale en-IN)
        • Flutter version 3.1.0-0.0.pre.2481 on channel master at C:\Users\Nabeel\fvm\versions\master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 91fdbfa7c8 (4 hours ago), 2022-08-25 03:07:06 -0400
        • Engine revision 9600c6c39b
        • Dart version 2.19.0 (build 2.19.0-137.0.dev)
        • DevTools version 2.16.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
        • Android SDK at C:\android-sdk
        • Platform android-33, build-tools 33.0.0
        • Java binary at: C:\Program Files\Java\jdk-17.0.4\bin\java
        • Java version Java(TM) SE Runtime Environment (build 17.0.4+11-LTS-179)
        • All Android licenses accepted.
    
    [✓] Chrome - develop for the web
        • CHROME_EXECUTABLE = C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe
    
    [✓] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.2.32630.192
        • Windows 10 SDK version 10.0.19041.0
    
    [!] Android Studio (not installed)
        • Android Studio not found; download from https://developer.android.com/studio/index.html
          (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
    
    [✓] VS Code (version 1.70.2)
        • VS Code at C:\Users\Nabeel\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension can be installed from:
          🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
    
    [✓] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.856]
        • Chrome (web)      • chrome  • web-javascript • unknown
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 104.0.1293.63
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
  3. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Aug 25, 2022
  4. DanTup commented on Aug 25, 2022

    @DanTup
    ContributorAuthor

    Reading the code here:

    observatoryUri = Stream<Uri>
    .fromFuture(
    buildObservatoryUri(
    device,
    debugUri?.host ?? hostname,
    debugPort ?? debugUri!.port,
    hostVmservicePort,
    debugUri?.path,
    )
    ).asBroadcastStream();

    Which calls here:

    Future<Uri> buildObservatoryUri(

    It looks like --debug-url might expect a device port, and not the host port. So I think it's setting up a new forwarded port to the supplied port on the device (where nothing is listening). It's possible that what I'm trying to do here is not supported (usually you'd use flutter attach with an app not launched with flutter run). If that's the case, the fix may be just to improve the description on --debug-url to make this clearer:

    'debug-url',
    aliases: <String>[ 'debug-uri' ], // supported for historical reasons
    help: 'The URL at which the observatory is listening.',

  5. added
    P3Issues that are less important to the Flutter project
    on Sep 6, 2022
  6. removed their assignment
    on Nov 17, 2022
  7. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    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

    P3Issues that are less important to the Flutter projectfound in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1found in release: 3.3Found to occur in 3.3has 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.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions