Skip to content

Commit 9c44284

Browse files
author
Anna Gringauze
authored
Fix hot restart hang if injected client throws an error (#1670)
* Fix hot restart hang if injected client throws an error * Address CR comments * Clean build to update the version
1 parent 23a4013 commit 9c44284

File tree

9 files changed

+2266
-2040
lines changed

9 files changed

+2266
-2040
lines changed

dwds/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
## 15.0.1-dev
1+
## 16.0.0-dev
2+
- Fix a hang and report errors on hot reload exceptions from the injected
3+
client.
4+
5+
**Breaking changes**
26
- Remove no longer used `ExpressionCompilerService.handler`.
7+
- Remove `assetHandler` parameter from `ExpressionCompilerService` constructor.
38

49
## 15.0.0
510
- Port some `dwds` files to null safety.

dwds/lib/src/debugging/inspector.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,13 @@ class AppInspector extends Domain {
314314
}
315315

316316
/// Evaluate [expression] by calling Chrome's Runtime.evaluate.
317-
Future<RemoteObject> jsEvaluate(String expression) async {
317+
Future<RemoteObject> jsEvaluate(String expression,
318+
{bool awaitPromise = false}) async {
318319
// TODO(alanknight): Support a version with arguments if needed.
319320
WipResponse result;
320321
result = await remoteDebugger.sendCommand('Runtime.evaluate', params: {
321322
'expression': expression,
323+
'awaitPromise': awaitPromise,
322324
'contextId': await contextId,
323325
});
324326
handleErrorIfPresent(result, evalContents: expression, additionalDetails: {

dwds/lib/src/dwds_vm_client.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import 'package:vm_service/vm_service.dart';
1313
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1414

1515
import 'events.dart';
16-
import 'services/chrome_proxy_service.dart' show ChromeProxyService;
16+
import 'services/chrome_proxy_service.dart';
17+
import 'services/chrome_debug_exception.dart';
1718
import 'services/debug_service.dart';
1819

1920
final _logger = Logger('DwdsVmClient');
@@ -187,10 +188,9 @@ Future<Map<String, dynamic>> _hotRestart(
187188

188189
chromeProxyService.terminatingIsolates = true;
189190
await _disableBreakpointsAndResume(client, chromeProxyService);
190-
int context;
191191
try {
192192
_logger.info('Attempting to get execution context ID.');
193-
context = await chromeProxyService.executionContext.id;
193+
await chromeProxyService.executionContext.id;
194194
_logger.info('Got execution context ID.');
195195
} on StateError catch (e) {
196196
// We couldn't find the execution context. `hotRestart` may have been
@@ -209,12 +209,9 @@ Future<Map<String, dynamic>> _hotRestart(
209209
// Generate run id to hot restart all apps loaded into the tab.
210210
final runId = const Uuid().v4().toString();
211211
_logger.info('Issuing \$dartHotRestartDwds request');
212-
await chromeProxyService.remoteDebugger
213-
.sendCommand('Runtime.evaluate', params: {
214-
'expression': '\$dartHotRestartDwds(\'$runId\');',
215-
'awaitPromise': true,
216-
'contextId': context,
217-
});
212+
await chromeProxyService
213+
.appInspectorProvider()
214+
.jsEvaluate('\$dartHotRestartDwds(\'$runId\');', awaitPromise: true);
218215
_logger.info('\$dartHotRestartDwds request complete.');
219216
} on WipError catch (exception) {
220217
final code = exception.error['code'];
@@ -229,6 +226,14 @@ Future<Map<String, dynamic>> _hotRestart(
229226
}
230227
};
231228
}
229+
} on ChromeDebugException catch (exception) {
230+
// Exceptions thrown by the injected client during hot restart.
231+
return {
232+
'error': {
233+
'code': RPCError.kInternalError,
234+
'message': '$exception',
235+
}
236+
};
232237
}
233238

234239
_logger.info('Waiting for Isolate Start event.');

0 commit comments

Comments
 (0)