From d7a0dcaa4af2a0bcd9025e8ecf55eae209460d40 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Tue, 11 Sep 2018 20:58:47 -0700 Subject: [PATCH] Fix race condition in resident_runner (#21696) * Don't set the `vmServices` member variable until it's fully initialized. * Add a timeout to the future that sends the 'started' event to the IDE https://github.com/flutter/flutter/issues/16604 --- packages/flutter_tools/lib/src/commands/daemon.dart | 7 ++++++- packages/flutter_tools/lib/src/resident_runner.dart | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 9fd00a4c968..5bb22bb99e2 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -423,7 +423,12 @@ class AppDomain extends Domain { final Completer appStartedCompleter = new Completer(); // We don't want to wait for this future to complete and callbacks won't fail. // As it just writes to stdout. - appStartedCompleter.future.then((_) { // ignore: unawaited_futures + appStartedCompleter.future.timeout(const Duration(minutes: 1), onTimeout: () { // ignore: unawaited_futures + _sendAppEvent(app, 'log', { + 'log': 'timeout waiting for the application to start', + 'error': true, + }); + }).then((_) { _sendAppEvent(app, 'started'); }); diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index d675e6db37f..57c4569a781 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -65,14 +65,15 @@ class FlutterDevice { Future _connect({ReloadSources reloadSources, CompileExpression compileExpression}) async { if (vmServices != null) return; - vmServices = new List(observatoryUris.length); + final List localVmServices = new List(observatoryUris.length); for (int i = 0; i < observatoryUris.length; i++) { printTrace('Connecting to service protocol: ${observatoryUris[i]}'); - vmServices[i] = await VMService.connect(observatoryUris[i], + localVmServices[i] = await VMService.connect(observatoryUris[i], reloadSources: reloadSources, compileExpression: compileExpression); printTrace('Successfully connected to service protocol: ${observatoryUris[i]}'); } + vmServices = localVmServices; } Future refreshViews() async {