From c5567a5fd2a04c1da8dab7494fa68b9c86e415fc Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 26 Sep 2016 17:12:20 -0700 Subject: [PATCH] Fix race condition locating observatory port on iOS (#6090) Ensure that we're monitoring logs before we launch the app on the device. This prevents the case where we start monitoring after the ports have already been logged. Also update the regex to use an optional capture group. --- .../flutter_tools/lib/src/ios/devices.dart | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index ac2b816cbb..3e4c37897f 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -249,6 +249,16 @@ class IOSDevice extends Device { // ports post launch. printTrace("Debugging is enabled, connecting to observatory and the diagnostic server"); + Future forwardObsPort = _acquireAndForwardPort(ProtocolDiscovery.kObservatoryService, + debuggingOptions.observatoryPort); + Future forwardDiagPort; + if (debuggingOptions.buildMode == BuildMode.debug) { + forwardDiagPort = _acquireAndForwardPort(ProtocolDiscovery.kDiagnosticService, + debuggingOptions.diagnosticPort); + } else { + forwardDiagPort = new Future.value(null); + } + Future launch = runCommandAndStreamOutput(launchCommand, trace: true); List ports = await launch.then((int result) async { @@ -260,17 +270,6 @@ class IOSDevice extends Device { } printTrace("Application launched on the device. Attempting to forward ports."); - - Future forwardObsPort = _acquireAndForwardPort(ProtocolDiscovery.kObservatoryService, - debuggingOptions.observatoryPort); - Future forwardDiagPort; - if (debuggingOptions.buildMode == BuildMode.debug) { - forwardDiagPort = _acquireAndForwardPort(ProtocolDiscovery.kDiagnosticService, - debuggingOptions.diagnosticPort); - } else { - forwardDiagPort = new Future.value(null); - } - return Future.wait(>[forwardObsPort, forwardDiagPort]); }); @@ -435,7 +434,7 @@ class _IOSDeviceLogReader extends DeviceLogReader { // // iOS 9 format: Runner[297] : // iOS 10 format: Runner(libsystem_asl.dylib)[297] : - static final RegExp _runnerRegex = new RegExp(r'Runner[(.*)]\[[\d]+\] <[A-Za-z]+>: '); + static final RegExp _runnerRegex = new RegExp(r'Runner(\(.*\))?\[[\d]+\] <[A-Za-z]+>: '); void _onLine(String line) { Match match = _runnerRegex.firstMatch(line);