authorgravatar for aleksey.kladov@gmail.comAlex Kladov <aleksey.kladov@gmail.com> 2024-08-20 17:34:20+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-19 11:50:38-08:00
log865ef245182a14f10e1e79371c80f14e9542c925
tree3fd395b6d354234350db2f860afda359b7391c55
parent8a00bd4ce6a3f7f61dc93ed8fabfee47f32dadc5

build: don't hang when capturing Stdout of verbose Build.Step.Run

When using Build.Step.Run.captureStdOut with a program that prints more than 10 megabytes of output, the build process hangs. This is because evalGeneric returns an error without reading child's stdin till the end, so we subsequently get stuck in `try child.wait()`. To fix this, make sure to kill the child in case of an error! Output before this change: λ ./zig/zig build -Dmultiversion=0.15.6 -Dconfig-release=0.15.7 -Dconfig-release-client-min=0.15.6 [3/8] steps └─ run gh ^C λ # an hour of debugging Output after this change: λ ./zig/zig build -Dmultiversion=0.15.6 -Dconfig-release=0.15.7 -Dconfig-release-client-min=0.15.6 install └─ install generated to ../tigerbeetle └─ run build_mutliversion (tigerbeetle) └─ run unzip └─ run gh failure error: unable to spawn gh: StdoutStreamTooLong Build Summary: 3/8 steps succeeded; 1 failed (disable with --summary none) install transitive failure └─ install generated to ../tigerbeetle transitive failure └─ run build_mutliversion (tigerbeetle) transitive failure └─ run unzip transitive failure └─ run gh failure error: the following build command failed with exit code 1: /home/matklad/p/tb/work/.zig-cache/o/c0e3f5e66ff441cd16f9a1a7e1401494/build /home/matklad/p/tb/work/zig/zig /home/matklad/p/tb/work /home/matklad/p/tb/work/.zig-cache /home/matklad/.cache/zig --seed 0xc1d4efc8 -Zaecc61299ff08765 -Dmultiversion=0.15.6 -Dconfig-release=0.15.7 -Dconfig-release-client-min=0.15.6

1 files changed, 7 insertions(+), 3 deletions(-)

lib/std/Build/Step/Run.zig+7-3
......@@ -1369,18 +1369,22 @@ fn spawnChildAndCollect(
13691369 defer if (inherit) std.debug.unlockStdErr();
13701370
13711371 try child.spawn();
1372 errdefer {
1373 _ = child.kill() catch {};
1374 }
1375
13721376 var timer = try std.time.Timer.start();
13731377
13741378 const result = if (run.stdio == .zig_test)
1375 evalZigTest(run, &child, prog_node, fuzz_context)
1379 try evalZigTest(run, &child, prog_node, fuzz_context)
13761380 else
1377 evalGeneric(run, &child);
1381 try evalGeneric(run, &child);
13781382
13791383 break :t .{ try child.wait(), result, timer.read() };
13801384 };
13811385
13821386 return .{
1383 .stdio = try result,
1387 .stdio = result,
13841388 .term = term,
13851389 .elapsed_ns = elapsed_ns,
13861390 .peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0,