Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #262 from mozilla-services/gh-259
Browse files Browse the repository at this point in the history
test: Fix intermittent failures with ReqwestClient
  • Loading branch information
ncloudioj authored Dec 7, 2021
2 parents e321f56 + 91ac2e1 commit 9d1f881
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 4 additions & 1 deletion merino-adm/src/remote_settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ impl RemoteSettingsSuggester {
config: &RemoteSettingsConfig,
metrics_client: StatsdClient,
) -> Result<Box<Self>, SetupError> {
let reqwest_client = ReqwestClient::try_new()
.context("Unable to create the Reqwest client")
.map_err(SetupError::Network)?;
let mut remote_settings_client = remote_settings_client::Client::builder()
.bucket_name(
config
Expand All @@ -63,7 +66,7 @@ impl RemoteSettingsSuggester {
folder: std::env::temp_dir(),
..remote_settings_client::client::FileStorage::default()
}))
.http_client(Box::new(ReqwestClient::new()))
.http_client(Box::new(reqwest_client))
.build()
.context("Unable to initialize the Remote Settings client")
.map_err(SetupError::InvalidConfiguration)?;
Expand Down
13 changes: 8 additions & 5 deletions merino-adm/src/remote_settings/reqwest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

//! An HTTP client implementation to use with the remote-settings-client.

use anyhow::Context;
use anyhow::{Context, Error};
use async_trait::async_trait;
use remote_settings_client::client::net::{
Headers as RsHeaders, Requester as RsRequester, Response as RsResponse, Url as RsUrl,
Expand All @@ -20,10 +20,13 @@ pub struct ReqwestClient {

impl ReqwestClient {
/// Instantiate a new Reqwest client to perform HTTP requests.
pub fn new() -> ReqwestClient {
Self {
reqwest_client: reqwest::Client::new(),
}
pub fn try_new() -> Result<ReqwestClient, Error> {
let reqwest_client = reqwest::Client::builder()
// Disable the connection pool to avoid the IncompleteMessage errors.
// See #259 for more details.
.pool_max_idle_per_host(0)
.build()?;
Ok(Self { reqwest_client })
}
}

Expand Down

0 comments on commit 9d1f881

Please sign in to comment.