Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: hyperium/hyper#2312
  • Loading branch information
demoray committed Jan 5, 2024
commit 99c1d0bcdf49a6ccf1615ddc53d0efaa4e0e78f0
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any adverse side effects of setting this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It effectively disables connection pools. This has a performance impact but mitigates a client hang.

In addition to the original reporter, I've experienced this issue as well. It's been an open issue in the hyper repo since October 2020.

.build()
.expect("failed to build `reqwest` client");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I would prefer to not add expect here, this mimics the behavior of reqwest::Client::new(). Moving new_reqwest_client to return a Result cascades into extensive changes.

https://github.com/seanmonstar/reqwest/blob/4f54ba732f80ccb89e50954a369d6e8bb46375f2/src/async_impl/client.rs#L1672-L1674

Arc::new(client)
}

#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
Expand Down