diff options
| author | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:29 +0100 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-11-04 01:11:29 +0100 |
| commit | 81c19a8a4f1c99f721d4c65fbcddcec6474b752b (patch) | |
| tree | 3b2320a40725420ef18669a15b1aa41e637e86c6 | |
| parent | tts: bound the audio cache and request length (diff) | |
| download | senator-sperma-81c19a8a4f1c99f721d4c65fbcddcec6474b752b.tar.gz senator-sperma-81c19a8a4f1c99f721d4c65fbcddcec6474b752b.zip | |
http: add connect and request timeouts
| -rw-r--r-- | src/commands/web.rs | 3 | ||||
| -rw-r--r-- | src/copyparty/mod.rs | 5 | ||||
| -rw-r--r-- | src/main.rs | 7 | ||||
| -rw-r--r-- | src/openrouter/mod.rs | 8 | ||||
| -rw-r--r-- | src/voice/mod.rs | 1 |
5 files changed, 21 insertions, 3 deletions
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 @@ | |||
| 1 | use std::time::Duration; | ||
| 2 | |||
| 1 | use poise::serenity_prelude as serenity; | 3 | use poise::serenity_prelude as serenity; |
| 2 | use scraper::{Html, Selector}; | 4 | use scraper::{Html, Selector}; |
| 3 | 5 | ||
| @@ -20,6 +22,7 @@ pub async fn web(ctx: Context<'_>, #[description = "Search query"] query: String | |||
| 20 | .data() | 22 | .data() |
| 21 | .http_client | 23 | .http_client |
| 22 | .get(&url) | 24 | .get(&url) |
| 25 | .timeout(Duration::from_secs(15)) | ||
| 23 | .send() | 26 | .send() |
| 24 | .await? | 27 | .await? |
| 25 | .text() | 28 | .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 { | |||
| 233 | base_url: base_url.trim_end_matches('/').to_string(), | 233 | base_url: base_url.trim_end_matches('/').to_string(), |
| 234 | upload_url: upload_url.trim_end_matches('/').to_string(), | 234 | upload_url: upload_url.trim_end_matches('/').to_string(), |
| 235 | password, | 235 | password, |
| 236 | client: Client::new(), | 236 | client: Client::builder() |
| 237 | .connect_timeout(Duration::from_secs(10)) | ||
| 238 | .build() | ||
| 239 | .unwrap_or_default(), | ||
| 237 | } | 240 | } |
| 238 | } | 241 | } |
| 239 | 242 | ||
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<dyn std::error::Error>> { | |||
| 149 | let config = config::Config::from_env(); | 149 | let config = config::Config::from_env(); |
| 150 | 150 | ||
| 151 | let db_pool = database::init_pool(&config.database_path).await?; | 151 | let db_pool = database::init_pool(&config.database_path).await?; |
| 152 | let http_client = reqwest::Client::new(); | 152 | // Connect timeout only: body timeouts are set per-call where a finite |
| 153 | // deadline makes sense (LLM/search/web), while media downloads may | ||
| 154 | // legitimately take a long time. | ||
| 155 | let http_client = reqwest::Client::builder() | ||
| 156 | .connect_timeout(Duration::from_secs(10)) | ||
| 157 | .build()?; | ||
| 153 | 158 | ||
| 154 | let copyparty = copyparty::CopypartyClient::new( | 159 | let copyparty = copyparty::CopypartyClient::new( |
| 155 | config.copyparty_url.clone(), | 160 | 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 @@ | |||
| 1 | use std::time::Duration; | ||
| 2 | |||
| 1 | use tracing::info; | 3 | use tracing::info; |
| 2 | 4 | ||
| 3 | use reqwest::Client; | 5 | use reqwest::Client; |
| @@ -49,7 +51,11 @@ impl OpenRouterClient { | |||
| 49 | api_key, | 51 | api_key, |
| 50 | model, | 52 | model, |
| 51 | api_url, | 53 | api_url, |
| 52 | client: Client::new(), | 54 | client: Client::builder() |
| 55 | .connect_timeout(Duration::from_secs(10)) | ||
| 56 | .timeout(Duration::from_secs(60)) | ||
| 57 | .build() | ||
| 58 | .unwrap_or_default(), | ||
| 53 | } | 59 | } |
| 54 | } | 60 | } |
| 55 | 61 | ||
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<Vec<u8>> { | |||
| 275 | pub async fn download_url(client: &reqwest::Client, url: &str) -> Result<Vec<u8>> { | 275 | pub async fn download_url(client: &reqwest::Client, url: &str) -> Result<Vec<u8>> { |
| 276 | let resp = client | 276 | let resp = client |
| 277 | .get(url) | 277 | .get(url) |
| 278 | .timeout(Duration::from_secs(300)) | ||
| 278 | .send() | 279 | .send() |
| 279 | .await | 280 | .await |
| 280 | .map_err(|e| Error::Custom(format!("HTTP GET failed for {}: {e}", redact_url(url))))?; | 281 | .map_err(|e| Error::Custom(format!("HTTP GET failed for {}: {e}", redact_url(url))))?; |
