Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work around hang issue in hyper #1550

Merged
merged 1 commit into from
Jan 5, 2024
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
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