From 2b4e287639c5c63c7b8fdd25ed5bacebf8561d88 Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 3 Jun 2024 14:44:46 +0800 Subject: [PATCH 1/2] test(download): fix clippy warnings regarding `Mutex` in `async` --- download/tests/read-proxy-env.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/download/tests/read-proxy-env.rs b/download/tests/read-proxy-env.rs index 435ef2692b..1ebc2843eb 100644 --- a/download/tests/read-proxy-env.rs +++ b/download/tests/read-proxy-env.rs @@ -4,15 +4,16 @@ use std::env::{remove_var, set_var}; use std::error::Error; use std::net::TcpListener; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::Mutex; use std::thread; use std::time::Duration; use env_proxy::for_url; +use once_cell::sync::Lazy; use reqwest::{Client, Proxy}; +use tokio::sync::Mutex; use url::Url; -static SERIALISE_TESTS: Mutex<()> = Mutex::new(()); +static SERIALISE_TESTS: Lazy> = Lazy::new(|| Mutex::new(())); fn scrub_env() { remove_var("http_proxy"); @@ -29,9 +30,7 @@ fn scrub_env() { // Tests for correctly retrieving the proxy (host, port) tuple from $https_proxy #[tokio::test] async fn read_basic_proxy_params() { - let _guard = SERIALISE_TESTS - .lock() - .expect("Unable to lock the test guard"); + let _guard = SERIALISE_TESTS.lock().await; scrub_env(); set_var("https_proxy", "http://proxy.example.com:8080"); let u = Url::parse("https://www.example.org").ok().unwrap(); @@ -45,9 +44,7 @@ async fn read_basic_proxy_params() { #[tokio::test] async fn socks_proxy_request() { static CALL_COUNT: AtomicUsize = AtomicUsize::new(0); - let _guard = SERIALISE_TESTS - .lock() - .expect("Unable to lock the test guard"); + let _guard = SERIALISE_TESTS.lock().await; scrub_env(); set_var("all_proxy", "socks5://127.0.0.1:1080"); From 6fdcbde5b99d08b5fa41edf439a98375b722227f Mon Sep 17 00:00:00 2001 From: rami3l Date: Mon, 3 Jun 2024 14:52:49 +0800 Subject: [PATCH 2/2] fix(download): work around `hyper` hang issue by adjusting `reqwest` config --- download/src/lib.rs | 4 ++++ download/tests/read-proxy-env.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/download/src/lib.rs b/download/src/lib.rs index 20b1bf2dc3..8c2f9892cc 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -345,6 +345,10 @@ pub mod reqwest_be { fn client_generic() -> ClientBuilder { Client::builder() + // HACK: set `pool_max_idle_per_host` to `0` to avoid an issue in the underlying + // `hyper` library that causes the `reqwest` client to hang in some cases. + // See for more details. + .pool_max_idle_per_host(0) .gzip(false) .proxy(Proxy::custom(env_proxy)) .timeout(Duration::from_secs(30)) diff --git a/download/tests/read-proxy-env.rs b/download/tests/read-proxy-env.rs index 1ebc2843eb..ca90983d38 100644 --- a/download/tests/read-proxy-env.rs +++ b/download/tests/read-proxy-env.rs @@ -61,6 +61,10 @@ async fn socks_proxy_request() { let url = Url::parse("http://192.168.0.1/").unwrap(); let client = Client::builder() + // HACK: set `pool_max_idle_per_host` to `0` to avoid an issue in the underlying + // `hyper` library that causes the `reqwest` client to hang in some cases. + // See for more details. + .pool_max_idle_per_host(0) .proxy(Proxy::custom(env_proxy)) .timeout(Duration::from_secs(1)) .build()