From 99c1d0bcdf49a6ccf1615ddc53d0efaa4e0e78f0 Mon Sep 17 00:00:00 2001 From: Brian Caswell Date: Fri, 5 Jan 2024 04:05:16 -0500 Subject: [PATCH] work around hang issue in hyper As indicated in #1549, there is an issue with hyper (the underlying layer used by reqwest) that hangs in some cases on connection pools. This PR uses a commonly discussed workaround of setting `pool_max_idle_per_host` to 0. Ref: https://github.com/hyperium/hyper/issues/2312 --- sdk/core/src/http_client/reqwest.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/sdk/core/src/http_client/reqwest.rs b/sdk/core/src/http_client/reqwest.rs index 419524ce8e..617fa5d73d 100644 --- a/sdk/core/src/http_client/reqwest.rs +++ b/sdk/core/src/http_client/reqwest.rs @@ -1,14 +1,24 @@ -use crate::error::{ErrorKind, ResultExt}; -use crate::{Body, HttpClient, PinnedStream}; - +use crate::{ + error::{ErrorKind, ResultExt}, + Body, HttpClient, PinnedStream, +}; use async_trait::async_trait; use futures::TryStreamExt; -use std::{collections::HashMap, str::FromStr}; +use std::{collections::HashMap, str::FromStr, sync::Arc}; /// Construct a new `HttpClient` with the `reqwest` backend. -pub fn new_reqwest_client() -> std::sync::Arc { +pub fn new_reqwest_client() -> Arc { log::debug!("instantiating an http client using the reqwest backend"); - std::sync::Arc::new(::reqwest::Client::new()) + + // 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. + let client = ::reqwest::ClientBuilder::new() + .pool_max_idle_per_host(0) + .build() + .expect("failed to build `reqwest` client"); + Arc::new(client) } #[cfg_attr(target_arch = "wasm32", async_trait(?Send))]