Skip to content

Commit 8e9476d

Browse files
committed
Defending pana log writes from cross-stream data + extra logging.
1 parent e78fa9d commit 8e9476d

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pkg/pub_worker/lib/src/analyze.dart

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:async';
6-
import 'dart:convert' show JsonUtf8Encoder, utf8;
6+
import 'dart:convert' show JsonUtf8Encoder, LineSplitter, utf8;
77
import 'dart:io'
88
show Directory, File, IOException, Platform, Process, ProcessSignal, gzip;
99
import 'dart:isolate' show Isolate;
@@ -152,12 +152,28 @@ Future<void> _analyzePackage(
152152
await pana.stdin.close();
153153

154154
await Future.wait<void>([
155-
pana.stderr.forEach(log.add),
156-
pana.stdout.forEach(log.add),
155+
pana.stderr
156+
.transform(utf8.decoder)
157+
.transform(LineSplitter())
158+
.forEach(log.writeln),
159+
pana.stdout
160+
.transform(utf8.decoder)
161+
.transform(LineSplitter())
162+
.forEach(log.writeln),
157163
pana.exitOrTimeout(_panaTimeout, () {
158164
log.writeln('TIMEOUT: pana sending SIGTERM/SIGKILL');
159165
}),
160-
]).catchError((e) => const [/* ignore */]);
166+
]).catchError((e, st) {
167+
log.writeln('Error waiting for pana process: $e');
168+
log.writeln(st);
169+
// kill the process if not already killed
170+
try {
171+
pana.kill(ProcessSignal.sigkill);
172+
} finally {
173+
// ignore
174+
}
175+
return const [];
176+
});
161177
final exitCode = await pana.exitCode;
162178

163179
log.writeln('### Execution of pana exited $exitCode');

0 commit comments

Comments
 (0)