From 81c19a8a4f1c99f721d4c65fbcddcec6474b752b Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 4 Nov 2026 01:11:29 +0100 Subject: http: add connect and request timeouts --- src/commands/web.rs | 3 +++ src/copyparty/mod.rs | 5 ++++- src/main.rs | 7 ++++++- src/openrouter/mod.rs | 8 +++++++- src/voice/mod.rs | 1 + 5 files changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/commands/web.rs b/src/commands/web.rs index d68f663..f8b8667 100644 --- a/src/commands/web.rs +++ b/src/commands/web.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use poise::serenity_prelude as serenity; use scraper::{Html, Selector}; @@ -20,6 +22,7 @@ pub async fn web(ctx: Context<'_>, #[description = "Search query"] query: String .data() .http_client .get(&url) + .timeout(Duration::from_secs(15)) .send() .await? .text() diff --git a/src/copyparty/mod.rs b/src/copyparty/mod.rs index 1f075a0..dfc43dc 100644 --- a/src/copyparty/mod.rs +++ b/src/copyparty/mod.rs @@ -233,7 +233,10 @@ impl CopypartyClient { base_url: base_url.trim_end_matches('/').to_string(), upload_url: upload_url.trim_end_matches('/').to_string(), password, - client: Client::new(), + client: Client::builder() + .connect_timeout(Duration::from_secs(10)) + .build() + .unwrap_or_default(), } } diff --git a/src/main.rs b/src/main.rs index 56f81cb..132e93b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,7 +149,12 @@ async fn main() -> Result<(), Box> { let config = config::Config::from_env(); let db_pool = database::init_pool(&config.database_path).await?; - let http_client = reqwest::Client::new(); + // Connect timeout only: body timeouts are set per-call where a finite + // deadline makes sense (LLM/search/web), while media downloads may + // legitimately take a long time. + let http_client = reqwest::Client::builder() + .connect_timeout(Duration::from_secs(10)) + .build()?; let copyparty = copyparty::CopypartyClient::new( config.copyparty_url.clone(), diff --git a/src/openrouter/mod.rs b/src/openrouter/mod.rs index 1d3b443..1b2caf4 100644 --- a/src/openrouter/mod.rs +++ b/src/openrouter/mod.rs @@ -1,3 +1,5 @@ +use std::time::Duration; + use tracing::info; use reqwest::Client; @@ -49,7 +51,11 @@ impl OpenRouterClient { api_key, model, api_url, - client: Client::new(), + client: Client::builder() + .connect_timeout(Duration::from_secs(10)) + .timeout(Duration::from_secs(60)) + .build() + .unwrap_or_default(), } } diff --git a/src/voice/mod.rs b/src/voice/mod.rs index bbb73a0..a6baa64 100644 --- a/src/voice/mod.rs +++ b/src/voice/mod.rs @@ -275,6 +275,7 @@ pub async fn ytdlp_download(url: &str) -> Result> { pub async fn download_url(client: &reqwest::Client, url: &str) -> Result> { let resp = client .get(url) + .timeout(Duration::from_secs(300)) .send() .await .map_err(|e| Error::Custom(format!("HTTP GET failed for {}: {e}", redact_url(url))))?; -- cgit v1.2.3