mirror of
https://github.com/nimbold/Firelink.git
synced 2026-09-01 05:29:23 +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 parity;
|
||||||
mod platform;
|
mod platform;
|
||||||
pub mod queue;
|
pub mod queue;
|
||||||
|
pub mod process;
|
||||||
pub mod retry;
|
pub mod retry;
|
||||||
mod settings;
|
mod settings;
|
||||||
pub use error::AppError;
|
pub use error::AppError;
|
||||||
@@ -2511,6 +2512,7 @@ pub(crate) async fn start_media_download_internal(
|
|||||||
let failure_reason = loop {
|
let failure_reason = loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
_ = cancel_rx.changed() => {
|
_ = cancel_rx.changed() => {
|
||||||
|
crate::process::kill_process_tree(child.pid());
|
||||||
let _ = child.kill();
|
let _ = child.kill();
|
||||||
if processing_started {
|
if processing_started {
|
||||||
cleanup_media_processing_artifacts(&out_path).await;
|
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