|  | 
| 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 | +}; | 
| 4 | 5 | use async_trait::async_trait; | 
| 5 | 6 | use futures::TryStreamExt; | 
| 6 |  | -use std::{collections::HashMap, str::FromStr}; | 
|  | 7 | +use std::{collections::HashMap, str::FromStr, sync::Arc}; | 
| 7 | 8 | 
 | 
| 8 | 9 | /// 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> { | 
| 10 | 11 |     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) | 
| 12 | 22 | } | 
| 13 | 23 | 
 | 
| 14 | 24 | #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] | 
|  | 
0 commit comments