diff options
| author | Alex Kladov <aleksey.kladov@gmail.com> | 2024-08-20 17:34:20 +0100 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-11-19 11:50:38 -0800 |
| commit | 865ef245182a14f10e1e79371c80f14e9542c925 (patch) | |
| tree | 3fd395b6d354234350db2f860afda359b7391c55 /lib/std | |
| parent | 8a00bd4ce6a3f7f61dc93ed8fabfee47f32dadc5 (diff) | |
| download | zig-865ef245182a14f10e1e79371c80f14e9542c925.tar.gz zig-865ef245182a14f10e1e79371c80f14e9542c925.zip | |
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
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/Build/Step/Run.zig | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index c35ba00b79..9db00460a9 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -1369,18 +1369,22 @@ fn spawnChildAndCollect( defer if (inherit) std.debug.unlockStdErr(); try child.spawn(); + errdefer { + _ = child.kill() catch {}; + } + var timer = try std.time.Timer.start(); const result = if (run.stdio == .zig_test) - evalZigTest(run, &child, prog_node, fuzz_context) + try evalZigTest(run, &child, prog_node, fuzz_context) else - evalGeneric(run, &child); + try evalGeneric(run, &child); break :t .{ try child.wait(), result, timer.read() }; }; return .{ - .stdio = try result, + .stdio = result, .term = term, .elapsed_ns = elapsed_ns, .peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0, |
