Repository: flutter
Issue: Lost connection to device on Android hot restart in CI AVD
Labels: c: crash,platform-android,tool,t: hot reload,P2,team-android,triaged-android

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Create a CI process that hot restarts your application in some way. For me, I'm using [convenient tester](https://github.com/fzyzcjy/flutter_convenient_test)
2. In my specifc case I use GithubActions with reactivecircus/android-emulator-runner@v2
3. Upon hot restarting the application (used in this particualr testing tool), flutter throws an exception and connection to the device is lost

**Expected results:**
The app to hot restart successfully so testing can continue

**Actual results:**
An exception is thrown and connection to the device is lost

Note that there was a similar issue #37818 which was merged so I've tested this on master as well as beta and stable. All three produce the same error.

There are also other users of the testing tool having the same problem, see fzyzcjy/flutter_convenient_test#188

Other points to note:

- the CI runner is using ubuntu (I've tried the Github Runner and a self hosted container solution).
- It does occasionally work but <10% of the time


<details>
  <summary>Logs</summary>

```
2022-10-21T08:57:17.0913380Z ✓  Built build/app/outputs/flutter-apk/app-debug.apk.
2022-10-21T08:59:37.9268984Z Installing build/app/outputs/flutter-apk/app-debug.apk...         128.0s
2022-10-21T09:02:08.6668738Z Unhandled exception:
2022-10-21T09:02:08.6669974Z s0.hotRestart: (-32000) Unable to restart: (-32603) 
2022-10-21T09:02:08.6670800Z #0      HotRunner._restartService (package:flutter_tools/src/run_hot.dart:183:7)
2022-10-21T09:02:08.6671323Z <asynchronous suspension>
2022-10-21T09:02:08.6672670Z #1      setUpVmService.<anonymous closure> (package:flutter_tools/src/vmservice.dart:211:7)
2022-10-21T09:02:08.6673301Z <asynchronous suspension>
2022-10-21T09:02:08.6673848Z #2      VmService._routeRequest (package:vm_service/src/vm_service.dart:2393:14)
2022-10-21T09:02:08.6674377Z <asynchronous suspension>
2022-10-21T09:02:08.6674886Z #3      VmService._processRequest (package:vm_service/src/vm_service.dart:2363:19)
2022-10-21T09:02:08.6675402Z <asynchronous suspension>
2022-10-21T09:02:08.6675654Z 
2022-10-21T09:02:08.6675953Z #0      new _OutstandingRequest (package:vm_service/src/vm_service.dart:1746)
2022-10-21T09:02:08.6676542Z #1      VmService._call (package:vm_service/src/vm_service.dart:2262)
2022-10-21T09:02:08.6677196Z #2      VmService.callServiceExtension (package:vm_service/src/vm_service.dart:2227)
2022-10-21T09:02:08.6677852Z #3      VmService.callMethod (package:vm_service/src/vm_service.dart:2215)
2022-10-21T09:02:08.6678619Z #4      __ServiceConnectionManager.callService (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:119)
2022-10-21T09:02:08.6679542Z #5      __ServiceConnectionManager._callServiceOnMainIsolate (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:106)
2022-10-21T09:02:08.6680215Z <asynchronous suspension>
2022-10-21T09:02:08.6680923Z #6      __ServiceConnectionManager.performHotRestart (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:100)
2022-10-21T09:02:08.6681604Z <asynchronous suspension>
2022-10-21T09:02:08.6682301Z #7      VmServiceWrapperService.hotRestartRaw.<anonymous closure> (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:48)
2022-10-21T09:02:08.6682981Z <asynchronous suspension>
2022-10-21T09:02:08.6685945Z #8      _BaseCounter.withPlusOneAsync (package:convenient_test_common_dart/src/common_dart/counter.dart:26)
2022-10-21T09:02:08.6686503Z <asynchronous suspension>
2022-10-21T09:02:08.6687193Z #9      VmServiceWrapperService.hotRestartRaw (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:47)
2022-10-21T09:02:08.6687839Z <asynchronous suspension>
2022-10-21T09:02:08.6690613Z #10     VmServiceWrapperService._hotRestartThrottledExecutor.<anonymous closure> (package:convenient_test_manager_dart/services/vm_service_wrapper_service.dart:53)
2022-10-21T09:02:08.6691372Z <asynchronous suspension>
2022-10-21T09:02:08.6692037Z #11     SingleRunningExecutor._trigger.<anonymous closure> (package:convenient_test_common_dart/src/common_dart/single_running_executor.dart:29)
2022-10-21T09:02:08.6692704Z <asynchronous suspension>
2022-10-21T09:02:08.7443656Z ##[error]The process '/bin/sh' failed with exit code 255
2022-10-21T09:02:08.7537085Z ##[group]Terminate Emulator
2022-10-21T09:02:08.7686029Z [command]/android-sdk/platform-tools/adb -s emulator-5554 emu kill
2022-10-21T09:02:09.0766564Z OK: killing emulator, bye bye
2022-10-21T09:02:09.0798983Z ##[endgroup]
2022-10-21T09:02:09.0992017Z Lost connection to device.
```

</details>