forge
Explore
Log in

Don't you dare go Hollow

ec-av1: bound every piped test child (1800s, EC_AV1_CHILD_TIMEOUT_SECS) -- a wedged aomenc dies loud instead of hanging the suite

Browse files at this commit

38b691941a1c5a3f3bc00d517af271ae301779baAhmet Kaan GümüşParent: 2b75a46
The CFL lane's suite lost 11h41m to a_segmentation_census's aomenc wedged
in anon_pipe_write: its tree predated the shared runner (a09c9c2a), so the
y4m went in via inline write_all and aomenc's stdout pipe filled first.
origin/main's run_with_stdin already drains stdin/stdout/stderr
concurrently, so the pipe-fill shape cannot recur -- but nothing bounded a
child that wedges for any other reason.

run_with_stdin now drains both output pipes on reader threads from the
first millisecond and enforces a deadline (default 1800 s, env override);
on expiry it kills, reaps, joins all three threads (bounded: the dead
child closed every pipe) and panics naming the command, the timeout, the
signal and the class, instead of hanging the suite until doomsday.

Class sweep: the runner is the crate's only stdin(Stdio::piped()) site
(148 spawn sites); every other child is stdin(null) + .output(), which
cannot deadlock on stdin.

Proof: census test green over all 10 real arms (4.1 s); wedged-child
probe (stub aomenc + 3 s bound) killed at 3.07 s with the class panic.
crates/ec-av1/src/probe.rsmodified+66 -4
@@ -124,22 +124,84 @@ pub fn source(
124124 /// carry the real diagnosis.
125125 ///
126126 /// # Panics
127-/// When the child cannot be spawned or reaped, or the writer thread panics.
127+/// When the child cannot be spawned or reaped, when the writer thread
128+/// panics, or when the child is still running after the deadline (below):
129+/// it is killed and the test fails naming the command, the timeout and the
130+/// kill -- the CFL suite lost 11h41m to a wedged aomenc child because the
131+/// pre-pipedrain spawn had no bound (class: aomenc-stdin-pipe-deadlock).
132+///
133+/// The deadline is 1800 s per child, overridable with
134+/// `EC_AV1_CHILD_TIMEOUT_SECS`. Every legitimate child here is an
135+/// aomenc/ffmpeg over an at-most-a-few-MB fixture: seconds, not minutes.
128136 #[cfg(test)]
129137 pub(crate) fn run_with_stdin(cmd: &mut Command, input: &[u8]) -> std::process::Output {
130- use std::io::Write;
138+ use std::io::{Read, Write};
131139 use std::process::Stdio;
140+ use std::time::{Duration, Instant};
141+
142+ let timeout = std::env::var("EC_AV1_CHILD_TIMEOUT_SECS")
143+ .ok()
144+ .and_then(|s| s.parse::<u64>().ok())
145+ .map_or(Duration::from_secs(1800), Duration::from_secs);
132146
133147 cmd.stdin(Stdio::piped())
134148 .stdout(Stdio::piped())
135149 .stderr(Stdio::piped());
136150 let mut child = cmd.spawn().expect("encoder failed to start");
137151 let mut stdin = child.stdin.take().expect("encoder stdin");
152+ let mut stdout = child.stdout.take().expect("encoder stdout");
153+ let mut stderr = child.stderr.take().expect("encoder stderr");
154+ let program = cmd.get_program().to_string_lossy().into_owned();
155+
138156 let payload = input.to_vec();
139157 let writer = std::thread::spawn(move || {
140158 let _ = stdin.write_all(&payload);
141159 });
142- let out = child.wait_with_output().expect("encoder failed to run");
160+ // Both output pipes drained from the first millisecond: the child can
161+ // never wedge on a full stdout/stderr pipe while we are still writing
162+ // stdin (the pre-pipedrain inline `write_all` + `wait_with_output`
163+ // pattern that deadlocked the CFL suite's census gate).
164+ let out_reader = std::thread::spawn(move || {
165+ let mut buf = Vec::new();
166+ let _ = stdout.read_to_end(&mut buf);
167+ buf
168+ });
169+ let err_reader = std::thread::spawn(move || {
170+ let mut buf = Vec::new();
171+ let _ = stderr.read_to_end(&mut buf);
172+ buf
173+ });
174+
175+ let deadline = Instant::now() + timeout;
176+ let status = loop {
177+ match child.try_wait().expect("encoder status") {
178+ Some(status) => break status,
179+ None if Instant::now() >= deadline => {
180+ let _ = child.kill();
181+ let killed = child.wait().expect("encoder reap");
182+ // The dead child closed every pipe, so all three threads
183+ // are out of their syscalls: the joins below are bounded.
184+ let _ = writer.join();
185+ let _ = out_reader.join();
186+ let _ = err_reader.join();
187+ panic!(
188+ "{program}: still running {secs}s after spawn -- killed ({killed}). \
189+ A live child here hangs the whole suite, which is how the CFL run lost \
190+ 11h41m to aomenc wedged in anon_pipe_write \
191+ (class: aomenc-stdin-pipe-deadlock). Check its wchan/fds before blaming \
192+ the decoder.",
193+ secs = timeout.as_secs(),
194+ );
195+ }
196+ None => std::thread::sleep(Duration::from_millis(50)),
197+ }
198+ };
199+ let out = out_reader.join().expect("encoder stdout reader thread");
200+ let err = err_reader.join().expect("encoder stderr reader thread");
143201 writer.join().expect("encoder stdin writer thread");
144- out
202+ std::process::Output {
203+ status,
204+ stdout: out,
205+ stderr: err,
206+ }
145207 }