Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reset the log stream readiness on every listen
  • Loading branch information
koji-1009 committed Oct 7, 2026
commit 2656461a7f9f6810bceb8ebd93dd44404df138b4
15 changes: 10 additions & 5 deletions packages/flutter_tools/lib/src/ios/simulators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,9 @@ class _IOSSimulatorLogReader extends SharedIOSDeviceLogReader {
///
/// `log stream` is ready once it prints its first line (a "Filtering the log
/// data using ..." header); events logged before that are dropped.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// data using ..." header); events logged before that are dropped.
/// data using ..." header).

I don't see where events are being dropped?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied, since the reason for waiting is already in the comment in startApp. 7223286

By "dropped" I meant that log stream doesn't deliver events logged before it prints that line, so in #181771 the Dart VM Service URL was never seen by the tool.

final _ready = Completer<void>();
///
/// Recreated on every listen, since each one starts a new `log stream`.
var _ready = Completer<void>();

@override
@visibleForTesting
Expand All @@ -888,12 +890,15 @@ class _IOSSimulatorLogReader extends SharedIOSDeviceLogReader {
String get name => device.name;

Future<void> _start() async {
// Use a local so that a previous process exiting late cannot complete it.
_ready = Completer<void>();
final Completer<void> ready = _ready;
// Unified logging iOS 11 and greater (introduced in iOS 10).
if (await device.sdkMajorVersion >= 11) {
_deviceProcess = await launchDeviceUnifiedLogging(device, _appName);
_deviceProcess?.stdout.transform(utf8LineDecoder).listen((String line) {
if (!_ready.isCompleted) {
_ready.complete();
if (!ready.isCompleted) {
ready.complete();
}
_onUnifiedLoggingLine(line);
});
Expand All @@ -918,8 +923,8 @@ class _IOSSimulatorLogReader extends SharedIOSDeviceLogReader {
// cleanup in the callback.
unawaited(
_deviceProcess?.exitCode.whenComplete(() {
if (!_ready.isCompleted) {
_ready.complete();
if (!ready.isCompleted) {
ready.complete();
}
if (_linesController.hasListener) {
_linesController.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1720,24 +1720,50 @@ Dec 20 17:04:32 md32-11-vm1 Another App[88374]: Ignore this text''',
);

testUsingContext(
'startApp waits for the log stream to be ready before launching the app',
'startApp waits for the log stream to be ready before each launch',
() {
// Regression test for https://github.com/flutter/flutter/issues/181771.
fakeAsync((FakeAsync async) {
final logProcess = FakeStreamingProcess();
processManager.addCommand(FakeCommand(command: logStreamCommand, process: logProcess));
final firstLogProcess = FakeStreamingProcess();
final secondLogProcess = FakeStreamingProcess();
processManager.addCommand(
FakeCommand(command: logStreamCommand, process: firstLogProcess),
);
processManager.addCommand(
FakeCommand(command: logStreamCommand, process: secondLogProcess),
);
final IOSSimulator device = buildDevice();
final IOSApp package = buildPackage();

buildDevice().startApp(
buildPackage(),
device.startApp(
package,
prebuiltApplication: true,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
);
async.elapse(const Duration(seconds: 1));
expect(simControl.requests, isEmpty);

logProcess.write('Filtering the log data using "type == 1024"\n');
firstLogProcess.write('Filtering the log data using "type == 1024"\n');
async.flushMicrotasks();
expect(simControl.requests, hasLength(1));

firstLogProcess.write(
'"eventMessage" : "The Dart VM service is listening on http://127.0.0.1:1234/abcdef/"\n',
);
async.elapse(const Duration(seconds: 1));

// The first launch stopped the log stream, so this one starts a new one.
device.startApp(
package,
prebuiltApplication: true,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
);
async.elapse(const Duration(seconds: 1));
expect(simControl.requests, hasLength(1));

secondLogProcess.write('Filtering the log data using "type == 1024"\n');
async.flushMicrotasks();
expect(simControl.requests, hasLength(2));
expect(processManager, hasNoRemainingExpectations);
});
},
Expand Down
Loading