From fd93334a21907f959018e1b1f5df747a98d186c8 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:11:50 +0100 Subject: processes: add timeouts and keep decoding off the runtime --- src/voice/mod.rs | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'src/voice') diff --git a/src/voice/mod.rs b/src/voice/mod.rs index a6baa64..5043508 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs @@ -237,22 +237,26 @@ fn decode_stream(mss: MediaSourceStream) -> Result { /// Download audio via yt-dlp, collect stdout into memory, return the raw bytes. /// Works for both finite media and live streams (yt-dlp handles the difference). pub async fn ytdlp_download(url: &str) -> Result> { - let output = tokio::process::Command::new("yt-dlp") - .args([ - "--ignore-config", - "-f", - "bestaudio", - "-o", - "-", - "--no-playlist", - "--", - url, - ]) - .stdout(std::process::Stdio::piped()) - .stderr(std::process::Stdio::piped()) - .output() - .await - .map_err(|e| Error::Custom(lang::fmt_voice_ytdlp_launch(&e)))?; + let output = tokio::time::timeout( + Duration::from_secs(600), + tokio::process::Command::new("yt-dlp") + .args([ + "--ignore-config", + "-f", + "bestaudio", + "-o", + "-", + "--no-playlist", + "--", + url, + ]) + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .output(), + ) + .await + .map_err(|_| Error::Custom("yt-dlp timed out after 10 minutes".into()))? + .map_err(|e| Error::Custom(lang::fmt_voice_ytdlp_launch(&e)))?; if !output.status.success() { let stderr = String::from_utf8_lossy(&output.stderr); -- cgit v1.2.3