use std::process::Child;
use std::thread;
use std::time::Duration;
use tracing::{info, warn};
pub async fn kill_and_reap_async(child: &mut Child) {
let _ = child.kill();
match child.wait() {
Ok(status) => {
info!(?status, "Browser process reaped successfully");
}
Err(e) => {
warn!(error = %e, "Failed to reap browser process");
}
}
}
pub fn kill_and_reap_sync(child: &mut Child, max_attempts: u32, retry_delay: Duration) {
let _ = child.kill();
for attempt in 1..=max_attempts {
match child.try_wait() {
Ok(Some(status)) => {
info!(
?status,
attempt, "Browser process reaped successfully in Drop"
);
return;
}
Ok(None) => {
if attempt < max_attempts {
thread::sleep(retry_delay);
}
}
Err(e) => {
warn!(error = %e, "Failed to check browser process status in Drop");
return;
}
}
}
warn!(
max_attempts,
"Browser process still running after kill, will become zombie until parent exits"
);
}