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

Reduce hyper client pool idle timeout to 20s #2384

Merged
merged 5 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
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
30 changes: 28 additions & 2 deletions rust/chains/hyperlane-ethereum/src/singleton_signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SignTask = (H256, Callback);
/// made at a time. Mostly useful for the AWS signers.
pub struct SingletonSigner {
inner: Signers,
retries: usize,
rx: mpsc::UnboundedReceiver<SignTask>,
}

Expand Down Expand Up @@ -62,13 +63,38 @@ impl SingletonSigner {
pub fn new(inner: Signers) -> (Self, SingletonSignerHandle) {
let (tx, rx) = mpsc::unbounded_channel::<SignTask>();
let address = inner.eth_address();
(Self { inner, rx }, SingletonSignerHandle { address, tx })
(
Self {
inner,
rx,
retries: 5,
},
SingletonSignerHandle { address, tx },
)
}

/// Change default (5) retries for signing
pub fn config_retries(&mut self, retries: usize) {
yorhodes marked this conversation as resolved.
Show resolved Hide resolved
self.retries = retries;
}

/// Run this signer's event loop.
pub async fn run(mut self) {
while let Some((hash, tx)) = self.rx.recv().await {
if tx.send(self.inner.sign_hash(&hash).await).is_err() {
let mut retries = self.retries;
let res = loop {
match self.inner.sign_hash(&hash).await {
Ok(res) => break Ok(res),
Err(err) => {
warn!("Error signing hash: {}", err);
if retries == 0 {
break Err(err);
}
retries -= 1;
}
}
};
if tx.send(res).is_err() {
warn!(
"Failed to send signature back to the signer handle because the channel was closed"
);
Expand Down
9 changes: 7 additions & 2 deletions rust/hyperlane-base/src/settings/signers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::time::Duration;

use async_trait::async_trait;
use ethers::prelude::{AwsSigner, LocalWallet};
use eyre::{bail, eyre, Context, Report};
use rusoto_core::{HttpClient, Region};
use rusoto_core::{HttpClient, HttpConfig, Region};
use rusoto_kms::KmsClient;
use serde::Deserialize;
use tracing::instrument;
Expand Down Expand Up @@ -104,10 +106,13 @@ impl BuildableWithSignerConf for hyperlane_ethereum::Signers {
),
)),
SignerConf::Aws { id, region } => {
let mut config = HttpConfig::new();
// see https://github.com/hyperium/hyper/issues/2136#issuecomment-589345238
config.pool_idle_timeout(Duration::from_secs(20));
let client = KmsClient::new_with_client(
rusoto_core::Client::new_with(
AwsChainCredentialsProvider::new(),
HttpClient::new().unwrap(),
HttpClient::new_with_config(config).unwrap(),
),
region.clone(),
);
Expand Down
Loading