Skip to content

Commit

Permalink
work around hang issue in hyper
Browse files Browse the repository at this point in the history
As indicated in Azure#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: hyperium/hyper#2312
  • Loading branch information
Brian Caswell committed Jan 5, 2024
1 parent e1773e1 commit 99c1d0b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions sdk/core/src/http_client/reqwest.rs
Original file line number Diff line number Diff line change
@@ -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<dyn HttpClient> {
pub fn new_reqwest_client() -> Arc<dyn HttpClient> {
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 <https://github.com/hyperium/hyper/issues/2312> 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))]
Expand Down

0 comments on commit 99c1d0b

Please sign in to comment.