mirror of
https://github.com/modrinth/code.git
synced 2026-08-30 11:36:05 +00:00
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
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<reqwest::Client> =
|
||||
LazyLock::new(|| {
|
||||
reqwest_client_builder_with_timeout()
|
||||
.build()
|
||||
.expect("client configuration should be valid")
|
||||
});
|
||||
|
||||
pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = 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<reqwest::Client> =
|
||||
LazyLock::new(|| {
|
||||
reqwest_client_builder()
|
||||
.build()
|
||||
.expect("client configuration should be valid")
|
||||
});
|
||||
|
||||
pub static REQWEST_CLIENT: LazyLock<reqwest::Client> = LazyLock::new(|| {
|
||||
reqwest_client_builder()
|
||||
.https_only(true)
|
||||
.build()
|
||||
.expect("client configuration should be valid")
|
||||
});
|
||||
pub static NO_TIMEOUT_REQWEST_CLIENT: LazyLock<reqwest::Client> =
|
||||
LazyLock::new(|| {
|
||||
reqwest_client_builder()
|
||||
.https_only(true)
|
||||
.build()
|
||||
.expect("client configuration should be valid")
|
||||
});
|
||||
|
||||
const FETCH_ATTEMPTS: usize = 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user