Skip to content

Commit 6e83506

Browse files
authored
[pigeon] Fix tool hangs on verbose sub-processes (flutter#6198)
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: flutter#6198 (comment) Needed for flutter#6196 Part of flutter/flutter#144042
1 parent 0aff69f commit 6e83506

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/pigeon/tool/shared/process_utils.dart

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,29 @@ Future<int> runProcess(String command, List<String> arguments,
1616
mode:
1717
streamOutput ? ProcessStartMode.inheritStdio : ProcessStartMode.normal,
1818
);
19+
20+
if (streamOutput) {
21+
return process.exitCode;
22+
}
23+
24+
final List<int> stdoutBuffer = <int>[];
25+
final List<int> stderrBuffer = <int>[];
26+
final Future<void> stdoutFuture = process.stdout.forEach(stdoutBuffer.addAll);
27+
final Future<void> stderrFuture = process.stderr.forEach(stderrBuffer.addAll);
1928
final int exitCode = await process.exitCode;
29+
await Future.wait(<Future<void>>[
30+
stdoutFuture,
31+
stderrFuture,
32+
]);
33+
2034
if (exitCode != 0 && logFailure) {
2135
// ignore: avoid_print
2236
print('$command $arguments failed:');
37+
stdout.add(stdoutBuffer);
38+
stderr.add(stderrBuffer);
2339
await Future.wait(<Future<void>>[
24-
process.stdout.pipe(stdout),
25-
process.stderr.pipe(stderr),
40+
stdout.flush(),
41+
stderr.flush(),
2642
]);
2743
}
2844
return exitCode;

0 commit comments

Comments
 (0)