Repository: flutter
Issue: Adding `--machine` to `flutter run` makes some terminating processes not terminate
Labels: platform-android,tool,P2,team-tool,triaged-tool

### Steps to reproduce

1. Connect a physical Android device with wifi-debugging
2. Make sure it is idle for enough time that it shows "offline" (see https://github.com/flutter/flutter/issues/154545 and https://github.com/Dart-Code/Dart-Code/issues/5245)
3. Try to run with `flutter run --machine -v`

### Expected results

For it to terminate as it did without the `--machine`.

### Actual results

Not terminating.

### Code sample

Not relevant.

### Screenshots or Video

Not relevant.

### Logs

<details open><summary>Logs</summary>

```console
[   +1 ms] Installing APK.
[{"event":"app.progress","params":{"appId":"61ae4db2-259b-4542-8b88-cee6cc9c9619","id":"1","progressId":null,"message":"Installing build\\app\\outputs\\flutter-apk\\app-debug.apk...","finished":false}}]
[   +1 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:41835 install -t -r C:\Users\felip_0vh5fa6\SUNSIG\trunk\Delphiap\Desenvol\Sunsoft
Flutter\Produtores\produtores\build\app\outputs\flutter-apk\app-debug.apk
[+66147 ms] Performing Streamed Install
                     Success
[{"event":"app.progress","params":{"appId":"61ae4db2-259b-4542-8b88-cee6cc9c9619","id":"1","progressId":null,"finished":true}}]
[   +2 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:41835 shell echo -n 5101296c28a4d3b4bcec0391818f743d79c04e91 > /data/local/tmp/sky.br.inf.sunsoft.produtores.sha1
[ +141 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:41835 shell -x logcat -v time -t 1
[ +490 ms] --------- beginning of main
                    09-03 09:32:57.448 D/NetdEventListenerService(27497): DNS Requested by : 101, 1000
[  +16 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:41835 shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x20000000 --ez enable-dart-profiling true   
--ez enable-checked-mode true --ez verify-entry-points true br.inf.sunsoft.produtores/br.inf.sunsoft.produtores.MainActivity
[ +215 ms] Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x20000000 cmp=br.inf.sunsoft.produtores/.MainActivity (has extras) }
[        ] Waiting for VM Service port to be available...
[+2922 ms] VM Service URL on device: http://127.0.0.1:37203/3ApRUPWnk_w=/
[   +1 ms] executing: C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk\platform-tools\adb.exe -s 192.168.200.50:41835 forward tcp:0 tcp:37203
[ +134 ms] 14918
[        ] Forwarded host port 14918 to device port 37203 for VM Service
[   +8 ms] Caching compiled dill
[ +117 ms] Connecting to service protocol: http://127.0.0.1:14918/3ApRUPWnk_w=/
[+31643 ms] Fail to connect to service protocol: http://127.0.0.1:14918/3ApRUPWnk_w=/: HttpException: Connection closed before full header was received, uri = http://127.0.0.1:14918/3ApRUPWnk_w=/ws
[   +2 ms] Error connecting to the service protocol: failed to connect to http://127.0.0.1:14918/3ApRUPWnk_w=/
[{"event":"app.stop","params":{"appId":"61ae4db2-259b-4542-8b88-cee6cc9c9619"}}]
[  +13 ms] I/flutter (30308): Drift: Sent SELECT * FROM sqlite_master; with args []
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[√] Flutter (Channel stable, 3.24.1, on Microsoft Windows [Version 10.0.22631.4037], locale pt-BR)
    • Flutter version 3.24.1 on channel stable at C:\Users\felip_0vh5fa6\.puro\envs\stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5874a72aa4 (2 weeks ago), 2024-08-20 16:46:00 -0500
    • Engine revision c9b9d5780d
    • Dart version 3.5.1
    • DevTools version 2.37.2

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at C:\Users\felip_0vh5fa6\AppData\Local\Android\sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: C:\Users\felip_0vh5fa6\AppData\Local\Programs\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 17.0.11+0--11852314)
    • 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.6)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.10.35201.131
    • Windows 10 SDK version 10.0.22621.0

[√] Android Studio (version 2024.1)
    • Android Studio at C:\Users\felip_0vh5fa6\AppData\Local\Programs\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.11+0--11852314)

[√] VS Code (version 1.92.2)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.92.0

[√] VS Code (version 1.88.0-insider)
    • VS Code at C:\Users\felip_0vh5fa6\AppData\Local\Programs\Microsoft VS Code Insiders
    • Flutter extension version 3.64.0

[√] Connected device (4 available)
    • SM G780F (mobile) • 192.168.200.50:41835 • android-arm64  • Android 13 (API 33)
    • Windows (desktop) • windows              • windows-x64    • Microsoft Windows [Version 10.0.22631.4037]
    • Chrome (web)      • chrome               • web-javascript • Google Chrome 128.0.6613.114
    • Edge (web)        • edge                 • web-javascript • Microsoft Edge 128.0.2739.42
    ! Device 192.168.200.50:39975 is offline.

[√] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>