Skip to content

Commit 16d098c

Browse files
author
Anna Gringauze
authored
Fix hot restart race by pausing the app before hot restart (#1361)
* Pause the app before hot restart A race between app hitting a breakpoint and a hot restart was causing hot restart to hang. Pause the app (if it is not already paused) forcefully before hot restarting to prevent this from happening. Closes: #1359 * Updated changelog
1 parent 7e138a7 commit 16d098c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

dwds/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## 11.1.2-dev
22

33
- Return empty library from `ChromeProxyService.getObject` for
4-
libraries present in medatata but not lodaded at runtime.
4+
libraries present in medatata but not loaded at runtime.
55
- Log failures to load kernel during expression evaluation.
66
- Show lowered final fields using their original dart names.
77
- Limit simultaneous connections to asset server to prevent broken sockets.
8+
- Fix hangs in hot restart.
89

910
## 11.1.1
1011

dwds/lib/src/dwds_vm_client.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,27 @@ class DwdsVmClient {
189189

190190
Future<void> _disableBreakpointsAndResume(
191191
VmService client, ChromeProxyService chromeProxyService) async {
192-
_logger.info('Attempting to disabling breakpoints and resume the isolate');
192+
_logger.info('Attempting to disable breakpoints and resume the isolate');
193193
var vm = await client.getVM();
194194
if (vm.isolates.isEmpty) throw StateError('No active isolate to resume.');
195195
var isolateRef = vm.isolates.first;
196+
197+
// Pause the app to prevent it from hitting a breakpoint
198+
// during hot restart and stalling hot restart execution.
199+
// Then wait for the app to pause or to hit a breakpoint.
200+
var debug = chromeProxyService.onEvent('Debug').firstWhere((event) =>
201+
event.kind == EventKind.kPauseInterrupted ||
202+
event.kind == EventKind.kPauseBreakpoint);
203+
204+
await client.pause(isolateRef.id);
205+
196206
var isolate = await client.getIsolate(isolateRef.id);
197-
await chromeProxyService.disableBreakpoints();
198-
if (isolate.pauseEvent.kind == EventKind.kPauseInterrupted ||
199-
isolate.pauseEvent.kind == EventKind.kPauseBreakpoint) {
200-
await client.resume(isolate.id);
207+
if (isolate.pauseEvent.kind != EventKind.kPauseInterrupted &&
208+
isolate.pauseEvent.kind != EventKind.kPauseBreakpoint) {
209+
await debug;
201210
}
211+
212+
await chromeProxyService.disableBreakpoints();
213+
await client.resume(isolateRef.id);
202214
_logger.info('Successfully disabled breakpoints and resumed the isolate');
203215
}

0 commit comments

Comments
 (0)