From 0fb86fed0797b3ab2a113cf6e1b37ce4f6f54c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 4 Nov 2026 02:57:49 +0100 Subject: [PATCH] Shorten the cleanup grace period in the e2e tests --- src/lib.rs | 14 +++++++++++++- tests/e2e/signals.rs | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f065262..dd712be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ use crate::sandbox::Bwrap; use crate::signals::ForwardedSignals; const CLEANUP_GRACE_PERIOD: Duration = Duration::from_secs(5); +const CLEANUP_GRACE_PERIOD_OVERRIDE: &str = "AGENT_SANDBOX_CLEANUP_GRACE_PERIOD_MS"; pub enum SandboxMode { Blacklist, @@ -114,6 +115,17 @@ pub fn run(config: SandboxConfig) -> Result { // bwrap ignores them: its death would SIGKILL the entrypoint through --die-with-parent. let bwrap_process = bwrap.spawn(signal_forwarder.ignore_forwarded_signals())?; let status = signal_forwarder.forward_until_exit(&bwrap_process)?; - process_tree::terminate_and_reap_all(CLEANUP_GRACE_PERIOD, signals::has_pending_interrupt)?; + process_tree::terminate_and_reap_all( + read_cleanup_grace_period(), + signals::has_pending_interrupt, + )?; Ok(status) } + +fn read_cleanup_grace_period() -> Duration { + std::env::var(CLEANUP_GRACE_PERIOD_OVERRIDE) + .ok() + .and_then(|milliseconds| milliseconds.parse().ok()) + .map(Duration::from_millis) + .unwrap_or(CLEANUP_GRACE_PERIOD) +} diff --git a/tests/e2e/signals.rs b/tests/e2e/signals.rs index 75d3b40..5238f93 100644 --- a/tests/e2e/signals.rs +++ b/tests/e2e/signals.rs @@ -134,6 +134,7 @@ fn run_with_detached_sleeper(sandbox_args: &[&str], setup: &str, marker: &str) { ); let status = Sandbox::new(sandbox_args) + .env("AGENT_SANDBOX_CLEANUP_GRACE_PERIOD_MS", "1000") .args(["--", "sh", "-c", &script]) .status() .expect("agent-sandbox binary failed to execute");