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

add timeout to provider::connect() in l1 update loop #2531

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
15 changes: 11 additions & 4 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl JsonRpcClient for MultiRpcClient {
};
let provider = current % self.clients.len();
let client = &self.clients[provider];

match client.request(method, &params).await {
Ok(res) => Ok(res),
Err(err) => {
Expand Down Expand Up @@ -331,10 +332,10 @@ impl L1Client {
let ws_urls = opt.l1_ws_provider.clone();
let retry_delay = opt.l1_retry_delay;
let subscription_timeout = opt.subscription_timeout;
let connect_timeout = opt.connect_timeout;
let state = self.state.clone();
let sender = self.sender.clone();
let metrics = self.metrics().clone();

let span = tracing::warn_span!("L1 client update");
async move {
for i in 0.. {
Expand All @@ -348,12 +349,17 @@ impl L1Client {
// problem with one of the hosts specifically.
let provider = i % urls.len();
let url = &urls[provider];
ws = match Provider::<Ws>::connect(url.clone()).await {
Ok(ws) => ws,
Err(err) => {
ws = match tokio::time::timeout(connect_timeout, Provider::<Ws>::connect(url.clone())).await {
Ok(Ok(ws)) => ws,
Ok(Err(err)) => {
tracing::warn!(provider, "failed to connect WebSockets provider: {err:#}");
sleep(retry_delay).await;
continue;
},
Err(_) => {
tracing::warn!(provider, "timed out connecting to WebSockets provider");
sleep(retry_delay).await;
continue;
}
};
ws.subscribe_blocks().await.map(StreamExt::boxed)
Expand Down Expand Up @@ -1253,6 +1259,7 @@ mod test {
} else {
None
},

..Default::default()
}
.connect([
Expand Down
9 changes: 9 additions & 0 deletions types/src/v0/v0_1/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ pub struct L1ClientOptions {
)]
pub l1_retry_delay: Duration,

/// Timeout for connecting to the L1 provider.
#[clap(
long,
env = "ESPRESSO_SEQUENCER_L1_CONNECT_TIMEOUT",
default_value = "2s",
value_parser = parse_duration,
)]
pub connect_timeout: Duration,

/// Request rate when polling L1.
#[clap(
long,
Expand Down