Repository: flutter
Issue: "flutter attach --debug-url" fails to attach to Windows app
Labels: tool,P2,team-tool,triaged-tool

### Steps to reproduce

1. Create a new app with `flutter create`
2. Run the app on Windows with `flutter run -d win`
3. Copy the URL of the VM Service that is printed
4. Try attaching in another terminal with `flutter attach --debug-url http://127.0.0.1:50334/_LZNB-xaZEg=/`

### Expected results

`flutter attach` should successfully attach to the running VM/application.

### Actual results

```
PS D:\Dev\Test Projects\dartcode_5371> flutter attach --debug-url http://127.0.0.1:50334/_LZNB-xaZEg=/
Error connecting to the service protocol: failed to connect to http://127.0.0.1:61528/_LZNB-xaZEg=/ HttpException: Connection closed before full header was received, uri = http://127.0.0.1:61528/_LZNB-xaZEg=/ws
```

### Code sample

N/A

### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

![image](https://github.com/user-attachments/assets/630e0948-7d68-43cf-a7b2-0d2061bfe2c0)

</details>


### Logs

<details open><summary>Logs</summary>

```console
PS D:\Dev\Test Projects\dartcode_5371> flutter attach -v --debug-url http://127.0.0.1:50334/_LZNB-xaZEg=/
[   +2 ms] Could not interpret results of "git describe": 3.27.0-1.0.pre.669
[ +112 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.
[  +23 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.
[  +18 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe devices -l
[  +30 ms] List of devices attached
           09011JEC209409         device product:sunfish model:Pixel_4a device:sunfish transport_id:1
[  +17 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s 09011JEC209409 forward tcp:0 tcp:50334
[   +6 ms] C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s 09011JEC209409 shell getprop
[  +18 ms] 61639
[  +46 ms] Connecting to service protocol: http://127.0.0.1:61639/_LZNB-xaZEg=/
[  +21 ms] Fail to connect to service protocol: http://127.0.0.1:61639/_LZNB-xaZEg=/: HttpException: Connection closed before full header was
received, uri = http://127.0.0.1:61639/_LZNB-xaZEg=/ws
[   +1 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:61639/_LZNB-xaZEg=/ HttpException: Connection closed before
full
           header was received, uri = http://127.0.0.1:61639/_LZNB-xaZEg=/ws
[   +1 ms] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s 09011JEC209409 forward --list
[  +18 ms] Exit code 0 from: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s 09011JEC209409 forward --list
[        ] 09011JEC209409 tcp:61639 tcp:50334
[        ] executing: C:\Users\danny\AppData\Local\Android\sdk\platform-tools\adb.exe -s 09011JEC209409 forward --remove tcp:61639
[  +22 ms] "flutter attach" took 243ms.
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
PS D:\Dev\Test Projects\dartcode_5371> flutter doctor -v
[!] Flutter (Channel master, 3.27.0-1.0.pre.669, on Microsoft Windows [Version 10.0.26100.2605], locale en-GB)
    • Flutter version 3.27.0-1.0.pre.669 on channel master at D:\Dev\Google\Flutter\Flutter main
    ! 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
    • FLUTTER_GIT_URL = git@github.com:DanTup/flutter.git
    • Framework revision a0ba2decab (3 weeks ago), 2024-11-29 18:20:31 +1000
    • Engine revision d7be573a5e
    • Dart version 3.7.0 (build 3.7.0-188.0.dev)
    • DevTools version 2.41.0-dev.2
    • 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)

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc3)
    • Android SDK at C:\Users\danny\AppData\Local\Android\sdk
    • Platform android-35, 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 17.0.9+0--11185874)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.10.5)
    • 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.22621.0

[✓] Android Studio (version 2023.2)
    • 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 17.0.9+0--11185874)

[✓] VS Code (version 1.96.0)
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.103.20241202

[✓] VS Code (version 1.93.0-insider)
    • VS Code at C:\Users\danny\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.95.20240801

[✓] Connected device (4 available)
    • Pixel 4a (mobile) • 09011JEC209409 • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows        • windows-x64    • Microsoft Windows [Version 10.0.26100.2605]
    • Chrome (web)      • chrome         • web-javascript • Google Chrome 131.0.6778.140
    • Edge (web)        • edge           • web-javascript • Microsoft Edge 127.0.2651.86

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>