Skip to content

Commit 38597f0

Browse files
authored
work around hang issue in hyper (#1550)
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
1 parent 5f9258f commit 38597f0

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

sdk/core/src/http_client/reqwest.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1-
use crate::error::{ErrorKind, ResultExt};
2-
use crate::{Body, HttpClient, PinnedStream};
3-
1+
use crate::{
2+
error::{ErrorKind, ResultExt},
3+
Body, HttpClient, PinnedStream,
4+
};
45
use async_trait::async_trait;
56
use futures::TryStreamExt;
6-
use std::{collections::HashMap, str::FromStr};
7+
use std::{collections::HashMap, str::FromStr, sync::Arc};
78

89
/// Construct a new `HttpClient` with the `reqwest` backend.
9-
pub fn new_reqwest_client() -> std::sync::Arc<dyn HttpClient> {
10+
pub fn new_reqwest_client() -> Arc<dyn HttpClient> {
1011
log::debug!("instantiating an http client using the reqwest backend");
11-
std::sync::Arc::new(::reqwest::Client::new())
12+
13+
// set `pool_max_idle_per_host` to `0` to avoid an issue in the underlying
14+
// `hyper` library that causes the `reqwest` client to hang in some cases.
15+
//
16+
// See <https://github.com/hyperium/hyper/issues/2312> for more details.
17+
let client = ::reqwest::ClientBuilder::new()
18+
.pool_max_idle_per_host(0)
19+
.build()
20+
.expect("failed to build `reqwest` client");
21+
Arc::new(client)
1222
}
1323

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

0 commit comments

Comments
 (0)