Fix issue where DevTools would not be immediately available when using --start-paused (#126698)
Service extensions are unable to handle requests when the isolate they were registered on is paused. The DevTools launcher logic was waiting for some service extension invocations to complete before advertising the already active DevTools instance, but when --start-paused was provided these requests would never complete, preventing users from using DevTools to resume the paused isolate. Fixes https://github.com/flutter/flutter/issues/126691
This commit is contained in:
@@ -35,6 +35,7 @@ abstract class ResidentDevtoolsHandler {
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
required List<FlutterDevice?> flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
});
|
||||
|
||||
bool launchDevToolsInBrowser({required List<FlutterDevice?> flutterDevices});
|
||||
@@ -71,6 +72,7 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
required List<FlutterDevice?> flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
}) async {
|
||||
assert(!_readyToAnnounce);
|
||||
if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) {
|
||||
@@ -88,20 +90,14 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
assert(!_readyToAnnounce);
|
||||
return;
|
||||
}
|
||||
final List<FlutterDevice?> devicesWithExtension = await _devicesWithExtensions(flutterDevices);
|
||||
await _maybeCallDevToolsUriServiceExtension(devicesWithExtension);
|
||||
await _callConnectedVmServiceUriExtension(devicesWithExtension);
|
||||
|
||||
if (_shutdown) {
|
||||
// If we're shutting down, no point reporting the debugger list.
|
||||
return;
|
||||
}
|
||||
_readyToAnnounce = true;
|
||||
assert(_devToolsLauncher!.activeDevToolsServer != null);
|
||||
|
||||
final Uri? devToolsUrl = _devToolsLauncher!.devToolsUrl;
|
||||
if (devToolsUrl != null) {
|
||||
for (final FlutterDevice? device in devicesWithExtension) {
|
||||
for (final FlutterDevice? device in flutterDevices) {
|
||||
if (device == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -111,11 +107,35 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> callServiceExtensions() async {
|
||||
final List<FlutterDevice?> devicesWithExtension = await _devicesWithExtensions(flutterDevices);
|
||||
await Future.wait(
|
||||
<Future<void>>[
|
||||
_maybeCallDevToolsUriServiceExtension(devicesWithExtension),
|
||||
_callConnectedVmServiceUriExtension(devicesWithExtension)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
// If the application is starting paused, we can't invoke service extensions
|
||||
// as they're handled on the target app's paused isolate. Since invoking
|
||||
// service extensions will block in this situation, we should wait to invoke
|
||||
// them until after we've output the DevTools connection details.
|
||||
if (!isStartPaused) {
|
||||
await callServiceExtensions();
|
||||
}
|
||||
|
||||
_readyToAnnounce = true;
|
||||
assert(_devToolsLauncher!.activeDevToolsServer != null);
|
||||
if (_residentRunner.reportedDebuggers) {
|
||||
// Since the DevTools only just became available, we haven't had a chance to
|
||||
// report their URLs yet. Do so now.
|
||||
_residentRunner.printDebuggerList(includeVmService: false);
|
||||
}
|
||||
|
||||
if (isStartPaused) {
|
||||
await callServiceExtensions();
|
||||
}
|
||||
}
|
||||
|
||||
// This must be guaranteed not to return a Future that fails.
|
||||
@@ -295,7 +315,11 @@ class NoOpDevtoolsHandler implements ResidentDevtoolsHandler {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> serveAndAnnounceDevTools({Uri? devToolsServerAddress, List<FlutterDevice?>? flutterDevices}) async {
|
||||
Future<void> serveAndAnnounceDevTools({
|
||||
Uri? devToolsServerAddress,
|
||||
List<FlutterDevice?>? flutterDevices,
|
||||
bool isStartPaused = false,
|
||||
}) async {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ class ColdRunner extends ResidentRunner {
|
||||
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
isStartPaused: debuggingOptions.startPaused,
|
||||
));
|
||||
}
|
||||
if (debuggingOptions.serveObservatory) {
|
||||
@@ -173,6 +174,7 @@ class ColdRunner extends ResidentRunner {
|
||||
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
isStartPaused: debuggingOptions.startPaused,
|
||||
));
|
||||
}
|
||||
if (debuggingOptions.serveObservatory) {
|
||||
|
||||
@@ -246,6 +246,7 @@ class HotRunner extends ResidentRunner {
|
||||
unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools(
|
||||
devToolsServerAddress: debuggingOptions.devToolsServerAddress,
|
||||
flutterDevices: flutterDevices,
|
||||
isStartPaused: debuggingOptions.startPaused,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user