mirror of
https://github.com/nimbold/Firelink.git
synced 2026-07-26 12:08:27 +00:00
fix(backend): recursively kill yt-dlp child processes to prevent zombies
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user