From fdb71de7a064b9f0282b8caada7495d58353d5ed Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Fri, 2 Jun 2023 07:31:07 -0700 Subject: [PATCH] Revert "Fix issue where DevTools would not be immediately available when using --start-paused" (#128117) Reverts flutter/flutter#126698 There are a bunch of tool crashes on CI that start with this commit. I'm not sure this PR is the cause because there is no backtrace from the tool on the crashes. The only error message is `Oops; flutter has exited unexpectedly: "Null check operator used on a null value`. --- .../lib/src/resident_devtools_handler.dart | 40 +++----------- packages/flutter_tools/lib/src/run_cold.dart | 2 - packages/flutter_tools/lib/src/run_hot.dart | 1 - .../resident_devtools_handler_test.dart | 4 +- .../integration.shard/devtools_uri_test.dart | 53 ------------------- 5 files changed, 10 insertions(+), 90 deletions(-) delete mode 100644 packages/flutter_tools/test/integration.shard/devtools_uri_test.dart diff --git a/packages/flutter_tools/lib/src/resident_devtools_handler.dart b/packages/flutter_tools/lib/src/resident_devtools_handler.dart index 17ee1f01ee7..2dc0aaef1ae 100644 --- a/packages/flutter_tools/lib/src/resident_devtools_handler.dart +++ b/packages/flutter_tools/lib/src/resident_devtools_handler.dart @@ -35,7 +35,6 @@ abstract class ResidentDevtoolsHandler { Future serveAndAnnounceDevTools({ Uri? devToolsServerAddress, required List flutterDevices, - bool isStartPaused = false, }); bool launchDevToolsInBrowser({required List flutterDevices}); @@ -72,7 +71,6 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { Future serveAndAnnounceDevTools({ Uri? devToolsServerAddress, required List flutterDevices, - bool isStartPaused = false, }) async { assert(!_readyToAnnounce); if (!_residentRunner.supportsServiceProtocol || _devToolsLauncher == null) { @@ -90,14 +88,20 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { assert(!_readyToAnnounce); return; } + final List 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 flutterDevices) { + for (final FlutterDevice? device in devicesWithExtension) { if (device == null) { continue; } @@ -107,35 +111,11 @@ class FlutterResidentDevtoolsHandler implements ResidentDevtoolsHandler { } } - Future callServiceExtensions() async { - final List devicesWithExtension = await _devicesWithExtensions(flutterDevices); - await Future.wait( - >[ - _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. @@ -315,11 +295,7 @@ class NoOpDevtoolsHandler implements ResidentDevtoolsHandler { } @override - Future serveAndAnnounceDevTools({ - Uri? devToolsServerAddress, - List? flutterDevices, - bool isStartPaused = false, - }) async { + Future serveAndAnnounceDevTools({Uri? devToolsServerAddress, List? flutterDevices}) async { return; } diff --git a/packages/flutter_tools/lib/src/run_cold.dart b/packages/flutter_tools/lib/src/run_cold.dart index cbd83bed033..88c3fd68e9c 100644 --- a/packages/flutter_tools/lib/src/run_cold.dart +++ b/packages/flutter_tools/lib/src/run_cold.dart @@ -86,7 +86,6 @@ class ColdRunner extends ResidentRunner { unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, - isStartPaused: debuggingOptions.startPaused, )); } if (debuggingOptions.serveObservatory) { @@ -174,7 +173,6 @@ class ColdRunner extends ResidentRunner { unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, - isStartPaused: debuggingOptions.startPaused, )); } if (debuggingOptions.serveObservatory) { diff --git a/packages/flutter_tools/lib/src/run_hot.dart b/packages/flutter_tools/lib/src/run_hot.dart index 7a02b984176..9dcf7e9ded6 100644 --- a/packages/flutter_tools/lib/src/run_hot.dart +++ b/packages/flutter_tools/lib/src/run_hot.dart @@ -246,7 +246,6 @@ class HotRunner extends ResidentRunner { unawaited(residentDevtoolsHandler!.serveAndAnnounceDevTools( devToolsServerAddress: debuggingOptions.devToolsServerAddress, flutterDevices: flutterDevices, - isStartPaused: debuggingOptions.startPaused, )); } diff --git a/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart b/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart index 56d933291e8..8c36d4e828b 100644 --- a/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_devtools_handler_test.dart @@ -156,7 +156,6 @@ void main() { }, ), listViews, - listViews, const FakeVmServiceRequest( method: 'ext.flutter.activeDevToolsServerAddress', args: { @@ -164,6 +163,7 @@ void main() { 'value': 'http://localhost:8080', }, ), + listViews, const FakeVmServiceRequest( method: 'ext.flutter.connectedVmServiceUri', args: { @@ -314,7 +314,6 @@ void main() { }, ), listViews, - listViews, const FakeVmServiceRequest( method: 'ext.flutter.activeDevToolsServerAddress', args: { @@ -322,6 +321,7 @@ void main() { 'value': 'http://localhost:8080', }, ), + listViews, const FakeVmServiceRequest( method: 'ext.flutter.connectedVmServiceUri', args: { diff --git a/packages/flutter_tools/test/integration.shard/devtools_uri_test.dart b/packages/flutter_tools/test/integration.shard/devtools_uri_test.dart deleted file mode 100644 index b667f39ff04..00000000000 --- a/packages/flutter_tools/test/integration.shard/devtools_uri_test.dart +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2014 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; - -import 'package:flutter_tools/src/base/file_system.dart'; -import 'package:flutter_tools/src/base/io.dart'; -import 'package:flutter_tools/src/convert.dart'; - -import '../src/common.dart'; -import 'test_data/basic_project.dart'; -import 'test_utils.dart'; - -void main() { - late Directory tempDir; - final BasicProject project = BasicProject(); - - setUp(() async { - tempDir = createResolvedTempDirectorySync('run_test.'); - await project.setUpIn(tempDir); - }); - - tearDown(() async { - tryToDelete(tempDir); - }); - - // Regression test for https://github.com/flutter/flutter/issues/126691 - testWithoutContext('flutter run --start-paused prints DevTools URI', () async { - final Completer completer = Completer(); - final RegExp matcher = RegExp(r'The Flutter DevTools debugger and profiler on'); - - final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter'); - final Process process = await processManager.start([ - flutterBin, - 'run', - '--start-paused', - '-d', - 'flutter-tester', - ], workingDirectory: tempDir.path); - - late StreamSubscription sub; - sub = process.stdout.transform(utf8.decoder).listen((String message) { - if (message.contains(matcher)) { - completer.complete(); - sub.cancel(); - } - }); - await completer.future; - process.kill(); - await process.exitCode; - }); -}