fix(backend): recursively kill yt-dlp child processes to prevent zombies

This commit is contained in:
NimBold
2026-06-29 10:46:14 +03:30
parent 34f4174213
commit 97b3489004
2 changed files with 28 additions and 0 deletions
+2
View File
@@ -1505,6 +1505,7 @@ pub mod ipc;
mod parity;
mod platform;
pub mod queue;
pub mod process;
pub mod retry;
mod settings;
pub use error::AppError;
@@ -2511,6 +2512,7 @@ pub(crate) async fn start_media_download_internal(
let failure_reason = loop {
tokio::select! {
_ = cancel_rx.changed() => {
crate::process::kill_process_tree(child.pid());
let _ = child.kill();
if processing_started {
cleanup_media_processing_artifacts(&out_path).await;
+26
View File
@@ -0,0 +1,26 @@
use sysinfo::System;
pub fn kill_process_tree(pid: u32) {
let mut sys = System::new();
sys.refresh_processes(sysinfo::ProcessesToUpdate::All, true);
let mut to_kill = vec![sysinfo::Pid::from_u32(pid)];
let mut i = 0;
while i < to_kill.len() {
let current_pid = to_kill[i];
for (p, process) in sys.processes() {
if process.parent() == Some(current_pid) {
if !to_kill.contains(p) {
to_kill.push(*p);
}
}
}
i += 1;
}
for p in to_kill.into_iter().rev() {
if let Some(process) = sys.process(p) {
process.kill();
}
}
}