Skip to content

Commit

Permalink
[pigeon] Fix tool hangs on verbose sub-processes (#6198)
Browse files Browse the repository at this point in the history
The Pigeon tool hangs on Windows if you don't have the Java formatter on your path. Repro examples:

```
dart ./tool/generate.dart
```

```
dart ./tool/test.dart -f windows_integration_tests
```

The root cause is that the tool runs sub-processes without consuming their stdout/stderr output. The sub-process blocks if these pipes get full. See: https://api.dart.dev/stable/3.3.0/dart-io/Process-class.html

This change is untested. See: #6198 (comment)

Needed for #6196

Part of flutter/flutter#144042
  • Loading branch information
loic-sharma authored Feb 26, 2024
1 parent 0aff69f commit 6e83506
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/pigeon/tool/shared/process_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ Future<int> runProcess(String command, List<String> arguments,
mode:
streamOutput ? ProcessStartMode.inheritStdio : ProcessStartMode.normal,
);

if (streamOutput) {
return process.exitCode;
}

final List<int> stdoutBuffer = <int>[];
final List<int> stderrBuffer = <int>[];
final Future<void> stdoutFuture = process.stdout.forEach(stdoutBuffer.addAll);
final Future<void> stderrFuture = process.stderr.forEach(stderrBuffer.addAll);
final int exitCode = await process.exitCode;
await Future.wait(<Future<void>>[
stdoutFuture,
stderrFuture,
]);

if (exitCode != 0 && logFailure) {
// ignore: avoid_print
print('$command $arguments failed:');
stdout.add(stdoutBuffer);
stderr.add(stderrBuffer);
await Future.wait(<Future<void>>[
process.stdout.pipe(stdout),
process.stderr.pipe(stderr),
stdout.flush(),
stderr.flush(),
]);
}
return exitCode;
Expand Down

0 comments on commit 6e83506

Please sign in to comment.