fix(native): name the pipe deadline when the child has exited (#1389)

Split out of #640 at review request: a translation PR is the wrong place for a process-handling change.

## What

When the direct child exits while a captured reader is still unfinished — a descendant holding a pipe, or output still being drained — `run_command_with_output` waits for the readers under the same deadline. On timeout the error said `<program> didn't finish within N seconds`, although the child had finished. It now says `<program> exited, but its output was still being captured at the N second deadline`, which names the shared deadline and does not claim the pipe is still open (`20026ee`).

In `inherited_pipe_tests`, an attempt whose direct child hit its own deadline before the holder filled both pipes proves nothing about inherited pipes, so the test retries it with a longer deadline, as it already did for an attempt that never reached the marker. The retry ceiling is a named `MAX_DEADLINE`.

## Testing

Run locally on Linux x86_64: `cargo test -p artcraft-launcher-native inherited_pipe_tests` passes (1 passed, 2 ignored fixtures), `cargo clippy -p artcraft-launcher-native --all-targets --locked -- -D warnings` is clean, and `cargo fmt --all -- --check` is clean. The wasm check was not run because this crate is not part of the web build. Hosted CI is left to run.
This commit is contained in:
Igor Bronovskyi authored and GitHub committed 2026-11-15 17:30:01 +01:00
1 parent 1421092b93
commit 7c613b4ccf
1 file changed
+11 -8
+11 -8
View File
@@ -122,9 +122,10 @@ fn run_command_with_output(mut cmd: Command, program: &str, timeout: Duration) -
};
// A descendant may retain a pipe after the direct child exits. Keep reader completion
// under the same deadline; on timeout the readers detach, as in the child timeout path.
// Say which deadline expired: the child's own, or the readers' after the child exited.
while !stdout.is_finished() || !stderr.is_finished() {
if start.elapsed() >= timeout {
return Err(format!("{program} didn't finish within {} seconds", timeout.as_secs()));
return Err(format!("{program} exited, but its output was still being captured at the {} second deadline", timeout.as_secs()));
}
std::thread::sleep(Duration::from_millis(15));
}
@@ -892,6 +893,7 @@ mod inherited_pipe_tests {
// The direct child has to start a second test process and fill both pipes before the
// deadline, which can take seconds on a slow or emulated machine. An attempt where it
// didn't get that far says nothing about inherited pipes: retry with a longer deadline.
const MAX_DEADLINE: Duration = Duration::from_secs(16);
let mut deadline = Duration::from_secs(1);
loop {
let holder = StopHolder(tempfile::tempdir().unwrap());
@@ -900,16 +902,17 @@ mod inherited_pipe_tests {
let start = Instant::now();
let result = run(exe.to_str().unwrap(), &args, deadline);
let elapsed = start.elapsed();
if !holder.0.path().join("parent-returning").exists() && deadline < Duration::from_secs(16) {
let parent_returned = holder.0.path().join("parent-returning").exists();
// The child timing out says nothing about the inherited pipes; its own deadline
// expired first, as does an attempt that never reached the marker.
let child_timeout = matches!(&result, Err(error) if error.contains("didn't finish within"));
if (!parent_returned || child_timeout) && deadline < MAX_DEADLINE {
deadline *= 4;
continue;
}
assert!(holder.0.path().join("parent-returning").exists(), "direct child did not exit its fixture within {deadline:?}");
assert!(
matches!(&result, Err(error) if error.contains("didn't finish within")),
"expected a pipe deadline error; helper returned success: {}, elapsed: {elapsed:?}",
result.is_ok()
);
assert!(parent_returned, "direct child did not exit its fixture within {deadline:?}");
let pipe_timeout = matches!(&result, Err(error) if error.contains("still being captured at the"));
assert!(pipe_timeout, "expected the inherited-pipe deadline, not the child's; helper returned {result:?}, elapsed: {elapsed:?}");
// The descendant would hold the pipes for HOLD, far past this bound.
assert!(deadline * 2 < HOLD);
assert!(elapsed < deadline * 2, "capture exceeded its caller deadline {deadline:?}: {elapsed:?}");