forge
Explore
Log in

Don't you dare go Hollow

Wait for SIGKILLed job processes to exit before checking them

Browse files at this commit

74e2f807ddf2cf0d524c042998726f9cd41101b2Ahmet Kaan GümüşParent: b495552
  • test
    • wait for SIGKILLed job processes to exit before checking them
Show full message
✅ test: wait for SIGKILLed job processes to exit before checking them

The executor reaps the job cgroup before run_job returns, and the cgroup is
gone by then. A SIGKILLed process leaves its cgroup before it finishes
exiting, so a single /proc check right after could still see it in state D.
Poll for up to 5 s instead.
crates/forge-runner/tests/integration/builtin.rsmodified+17 -1
@@ -253,6 +253,19 @@ fn process_gone(pid: u32) -> bool {
253253 }
254254 }
255255
256+/// Waits up to five seconds for `pid` to exit. A SIGKILLed process leaves its cgroup before it
257+/// finishes exiting, so a single check right after the cgroup is gone can still see it running.
258+async fn wait_gone(pid: u32) -> bool {
259+ let deadline = Instant::now() + Duration::from_secs(5);
260+ while !process_gone(pid) {
261+ if Instant::now() >= deadline {
262+ return false;
263+ }
264+ tokio::time::sleep(Duration::from_millis(20)).await;
265+ }
266+ true
267+}
268+
256269 /// The helper is SIGKILLed while its job is still running, so it cannot tear the container down.
257270 /// The executor must then kill the job's processes, remove its cgroup, and remove its job dir.
258271 #[tokio::test]
@@ -298,7 +311,10 @@ async fn sigkilled_helper_leaves_no_process_behind() {
298311 cgroup.display()
299312 );
300313 for pid in &procs {
301- assert!(process_gone(*pid), "job process {pid} survived the helper");
314+ assert!(
315+ wait_gone(*pid).await,
316+ "job process {pid} survived the helper"
317+ );
302318 }
303319 assert!(!dir.path().join("jobs/job_01").exists(), "job dir was kept");
304320 }