Repository: flutter
Issue: 'flutter run' daemon hot-restart requests do not complete if made while isolates are still paused from a prior hot restart
Labels: tool,team-tool

### Steps to reproduce

Some issues have come up with VS Code showing "Hot Restart..." progress indicators getting stuck:

- https://github.com/Dart-Code/Dart-Code/issues/4980
- https://twitter.com/luke_pighetti/status/1756870430550343907

I was able to reproduce this with a new Flutter app by hitting the Restart button on the VS Code debug toolbar many times quickly.

I believe the issue is inside Flutter (/the run daemon). I was able to reproduce what I believe is the same issue without VS Code or DAP using a script that spawns and interacts with the daemon.

https://gist.github.com/DanTup/757445d7303c4fc8fc0552086b5f3b4b

This script (placed inside the `tool` folder of a Flutter app) will run the app with `flutter run --machine --start-paused` and then send two hot-restart requests without unpausing the isolates in between (this is to simulate a user sending a second hot restart before the IDE had finished setting up breakpoints etc. and resuming).

The output on my machine looks like this:

```
Connecting to VM Service at ws://127.0.0.1:59349/d90tdEP8YtU=/ws
<== Changing current working directory to: C:\Dev\Test Projects\dartcode_4980
<== [{"event":"daemon.connected","params":{"version":"0.6.1","pid":16568}}]
<== [{"event":"app.start","params":{"appId":"434eb71c-62eb-4341-8b84-6cdf26b76531","deviceId":"windows","directory":"C:\\Dev\\Test Projects\\dartcode_4980","supportsRestart":true,"launchMode":"run","mode":"debug"}}]
<== Launching lib\main.dart on Windows in debug mode...
<== √  Built build\windows\x64\runner\Debug\dartcode_4980.exe.
<== [{"event":"app.debugPort","params":{"appId":"434eb71c-62eb-4341-8b84-6cdf26b76531","port":59360,"wsUri":"ws://127.0.0.1:59360/PnB3qskTsUw=/ws","baseUri":"file:///C:/Users/danny/AppData/Local/Temp/dartcode_49802f11d9a4/dartcode_4980/"}}]
<== [{"event":"app.started","params":{"appId":"434eb71c-62eb-4341-8b84-6cdf26b76531"}}]
==> [{"id":1,"method":"app.restart","params":{"appId":"434eb71c-62eb-4341-8b84-6cdf26b76531","fullRestart":true}}]
==> [{"id":2,"method":"app.restart","params":{"appId":"434eb71c-62eb-4341-8b84-6cdf26b76531","fullRestart":true}}]
<== Restarted application in 261ms.
<== [{"id":1,"result":{"code":0,"message":""}}]
```

The line `<== [{"id":1,"result":{"code":0,"message":""}}]` is the response from the daemon for the first hot reload request. However, request 2 was never responded to. In the debug adapter, this means they never complete (and this means the progress indicators are never removed).

My suspicion is that this occurs if a hot reload request arrives when the isolates are still paused from the previous one (due to `--start-paused`).


### Expected results

Every hot restart request to the daemon should be responded to, no matter how the timing overlaps with other restarts.

### Actual results

The daemon never responds to some of the requests.

### Code sample

https://gist.github.com/DanTup/757445d7303c4fc8fc0552086b5f3b4b

### Screenshots or Video

_No response_

### Logs

_No response_

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
PS C:\Dev> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel master, 3.20.0-6.0.pre.50, on Microsoft Windows [Version 10.0.22621.3007], locale en-GB)
    ! Warning: `dart` on your path resolves to C:\Dev\Tools\Dart\Stable\bin\dart.exe, which is not inside your current Flutter SDK checkout at
      C:\Dev\Google\flutter. Consider adding C:\Dev\Google\flutter\bin to the front of your path.
[✓] Windows Version (Installed version of Windows is version 10 or higher)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.7.4)
[✓] Android Studio (version 2022.3)
[✓] VS Code (version 1.86.1)
[✓] VS Code (version 1.86.0-insider)
[✓] Connected device (3 available)
[✓] Network resources
```

</details>