From 74205607840573a0d5f07907852b2c7128008e84 Mon Sep 17 00:00:00 2001 From: Sychic <47618543+Sychic@users.noreply.github.com> Date: Tue, 25 Aug 2026 14:28:47 -0400 Subject: [PATCH] fix(app-lib): remove timeout for shared instance uploads (#7304) * fix(app-lib): remove timeout for shared instance uploads * style(app-lib): cargo fmt * style(app-lib): remove unused import --- .../app-lib/src/api/instance/shared/client.rs | 12 +++++- .../app-lib/src/api/instance/shared/mod.rs | 5 ++- packages/app-lib/src/util/fetch.rs | 38 ++++++++++++++----- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/packages/app-lib/src/api/instance/shared/client.rs b/packages/app-lib/src/api/instance/shared/client.rs index 52fdc788cf..7452e99464 100644 --- a/packages/app-lib/src/api/instance/shared/client.rs +++ b/packages/app-lib/src/api/instance/shared/client.rs @@ -874,7 +874,7 @@ pub(super) async fn send_bytes_request_to_url( "Sending shared instances API request" ); - let mut request = shared_instances_client(url) + let mut request = shared_instances_upload_client(url) .request(method.clone(), url) .bearer_auth(credentials.session) .header(reqwest::header::CONTENT_TYPE, "application/octet-stream") @@ -1063,3 +1063,13 @@ pub(super) fn shared_instances_client( &INSECURE_REQWEST_CLIENT } } + +pub(super) fn shared_instances_upload_client( + base_url: &str, +) -> &'static reqwest::Client { + if base_url.starts_with("https://") { + &NO_TIMEOUT_REQWEST_CLIENT + } else { + &INSECURE_NO_TIMEOUT_REQWEST_CLIENT + } +} diff --git a/packages/app-lib/src/api/instance/shared/mod.rs b/packages/app-lib/src/api/instance/shared/mod.rs index b13cae82e8..7706a4f841 100644 --- a/packages/app-lib/src/api/instance/shared/mod.rs +++ b/packages/app-lib/src/api/instance/shared/mod.rs @@ -15,7 +15,10 @@ use crate::state::{ ContentSourceKind, EditInstance, ModLoader, ModrinthCredentials, ProjectType, SharedInstanceRole, State, }; -use crate::util::fetch::{INSECURE_REQWEST_CLIENT, REQWEST_CLIENT}; +use crate::util::fetch::{ + INSECURE_NO_TIMEOUT_REQWEST_CLIENT, INSECURE_REQWEST_CLIENT, + NO_TIMEOUT_REQWEST_CLIENT, REQWEST_CLIENT, +}; use chrono::{DateTime, Utc}; use reqwest::{Method, StatusCode}; use serde::de::DeserializeOwned; diff --git a/packages/app-lib/src/util/fetch.rs b/packages/app-lib/src/util/fetch.rs index 17c0ec002e..2730ca8d18 100644 --- a/packages/app-lib/src/util/fetch.rs +++ b/packages/app-lib/src/util/fetch.rs @@ -19,7 +19,7 @@ use std::num::NonZeroU32; use std::path::Path; use std::pin::Pin; use std::sync::{Arc, LazyLock}; -use std::time::{self, Duration, Instant, SystemTime}; +use std::time::{Duration, Instant, SystemTime}; use tokio::sync::Semaphore; use tokio::{fs::File, io::AsyncReadExt, io::AsyncWriteExt}; use tracing::{debug, info}; @@ -330,27 +330,45 @@ fn duration_seconds_ceil(duration: Duration) -> u64 { .saturating_add(u64::from(duration.subsec_nanos() > 0)) } +fn reqwest_client_builder_with_timeout() -> reqwest::ClientBuilder { + reqwest_client_builder().read_timeout(Duration::from_secs(30)) +} + fn reqwest_client_builder() -> reqwest::ClientBuilder { reqwest::Client::builder() - .connect_timeout(time::Duration::from_secs(15)) - .read_timeout(time::Duration::from_secs(30)) - .tcp_keepalive(Some(time::Duration::from_secs(10))) + .connect_timeout(Duration::from_secs(15)) + .tcp_keepalive(Some(Duration::from_secs(10))) .user_agent(crate::launcher_user_agent()) } pub static INSECURE_REQWEST_CLIENT: LazyLock = + LazyLock::new(|| { + reqwest_client_builder_with_timeout() + .build() + .expect("client configuration should be valid") + }); + +pub static REQWEST_CLIENT: LazyLock = LazyLock::new(|| { + reqwest_client_builder_with_timeout() + .https_only(true) + .build() + .expect("client configuration should be valid") +}); + +pub static INSECURE_NO_TIMEOUT_REQWEST_CLIENT: LazyLock = LazyLock::new(|| { reqwest_client_builder() .build() .expect("client configuration should be valid") }); -pub static REQWEST_CLIENT: LazyLock = LazyLock::new(|| { - reqwest_client_builder() - .https_only(true) - .build() - .expect("client configuration should be valid") -}); +pub static NO_TIMEOUT_REQWEST_CLIENT: LazyLock = + LazyLock::new(|| { + reqwest_client_builder() + .https_only(true) + .build() + .expect("client configuration should be valid") + }); const FETCH_ATTEMPTS: usize = 2;