Skip to content

Commit

Permalink
fix: replace network subgraph processing timeout with warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Feb 13, 2025
1 parent 8a7548b commit b0d0df4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/network/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ use thegraph_core::{
alloy::primitives::{Address, BlockNumber},
DeploymentId, IndexerId, SubgraphId,
};
use tokio::{sync::watch, time::MissedTickBehavior};
use tokio::{
sync::watch,
time::{Instant, MissedTickBehavior},
};

use super::{
cost_model::CostModelResolver,
Expand Down Expand Up @@ -213,10 +216,14 @@ fn spawn_updater_task(
loop {
timer.tick().await;

match fetch_and_preprocess_subgraph_info(&mut subgraph_client, update_interval).await {
let start_time = Instant::now();
match fetch_and_preprocess_subgraph_info(&mut subgraph_client).await {
Ok(info) => network_info = Some(info),
Err(network_subgraph_update_err) => tracing::error!(%network_subgraph_update_err),
};
if start_time.elapsed() > (update_interval * 2) {
tracing::warn!("subgraph processing taking too long");
}
let network_info = match &network_info {
Some(info) => info,
None => continue,
Expand Down Expand Up @@ -251,10 +258,9 @@ fn spawn_updater_task(
/// Invalid info is filtered out before converting into the internal representation.
pub async fn fetch_and_preprocess_subgraph_info(
client: &mut SubgraphClient,
timeout: Duration,
) -> anyhow::Result<PreprocessedNetworkInfo> {
// Fetch the subgraphs information from the graph network subgraph
let data = tokio::time::timeout(timeout, client.fetch()).await??;
let data = client.fetch().await?;
anyhow::ensure!(!data.is_empty(), "empty subgraph response");

// Pre-process (validate and convert) the fetched subgraphs information
Expand Down

0 comments on commit b0d0df4

Please sign in to comment.