Repository: flutter
Issue: Error connecting to the service protocol: failed to connect to http://127.0.0.1:#####/
Labels: c: crash,e: device-specific,platform-android,tool,P3,team-android,triaged-android


I get this error when debugging on Android devices, since I upgraded to Flutter 2 it seems...

```
Built build\app\outputs\flutter-apk\app-debug.apk.
Error connecting to the service protocol: failed to connect to http://127.0.0.1:63031/ihu8-A9J5E4=/
Exited (sigterm)

```

flutter run log:

```
[9:27:36 AM]: Spawning C:\Apps\flutter\bin\flutter.bat with args ["run","--machine","--target","lib\\main.dart","-d","420040159a4d539b","--dart-define=flutter.inspector.structuredErrors=true","--start-paused","--web-server-debug-protocol","ws","--web-allow-expose-url","--devtools-server-address","http://127.0.0.1:9100/"]
[9:27:36 AM]: ..  in D:\DEV\MedicLite
[9:27:36 AM]: ..  with {"toolEnv":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code"}}
[9:27:36 AM]: PID: 11980
[9:27:40 AM]: <== [{"event":"daemon.connected","params":{"version":"0.6.0","pid":10328}}]
[9:27:40 AM]: <== [{"event":"app.start","params":{"appId":"50e70b39-14b4-4c03-98e1-c95052f116ef","deviceId":"420040159a4d539b","directory":"D:\\DEV\\MedicLite","supportsRestart":true,"launchMode":"run"}}]
[9:27:40 AM]: <== Launching lib\main.dart on SM J120W in debug mode...
[9:27:40 AM]: <== [{"event":"app.progress","params":{"appId":"50e70b39-14b4-4c03-98e1-c95052f116ef","id":"0","progressId":null,"message":"Running Gradle task 'assembleDebug'...","finished":false}}]
[9:27:42 AM]: <== I/FlutterBackgroundExecutor( 4948): Starting AlarmService...
[9:27:42 AM]: <== I/flutter ( 4948): initialize test = true
[9:27:42 AM]: <== I/flutter ( 4948): initState
[9:27:42 AM]: <== I/flutter ( 4948): loadData
[9:27:42 AM]: <== I/flutter ( 4948): loadData done
[9:27:52 AM]: <== [{"event":"app.progress","params":{"appId":"50e70b39-14b4-4c03-98e1-c95052f116ef","id":"0","progressId":null,"finished":true}}]
[9:27:52 AM]: <== √  Built build\app\outputs\flutter-apk\app-debug.apk.
[9:27:59 AM]: Error connecting to the service protocol: failed to connect to http://127.0.0.1:63031/ihu8-A9J5E4=/
[9:27:59 AM]: <== [{"event":"app.stop","params":{"appId":"50e70b39-14b4-4c03-98e1-c95052f116ef"}}]

```

I never had this issue before debugging multiple android projects on 2 different devices.

**WORKAROUND**: I need to reboot the device before each "Start Debugging" session in VSCode.

```
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19042.1052], locale en-US)
    • Flutter version 2.2.1 at C:\Apps\flutter
    • Framework revision 02c026b03c (13 days ago), 2021-05-27 12:24:44 -0700
    • Engine revision 0fdb562ac8
    • Dart version 2.13.1

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)        
    • Android SDK at C:\Users\Michel\AppData\Local\Android\sdk
    • Platform android-30, build-tools 29.0.2
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Android Studio
    • 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
    • android-studio-dir = C:\Program Files\Android\Android Studio
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6842174)

[√] VS Code (version 1.56.2)
    • VS Code at C:\Users\Michel\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.0.2

[√] Connected device (3 available)
    • SM J120W (mobile) • 420040159a4d539b • android-arm    • Android 6.0.1 (API 23)    
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 91.0.4472.77
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 88.0.705.74

• No issues found!

```