Skip to content

Commit 009b909

Browse files
authored
Merge pull request #33 from graphprotocol/pcv/timeouts-everywhere
fix: use timeouts in all requests to subgraphs
2 parents 28312fd + 19e59c1 commit 009b909

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

availability-oracle/src/epoch_block_oracle_subgraph.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize};
66
use std::collections::BTreeMap;
77
use std::pin::Pin;
88
use std::sync::Arc;
9-
9+
use std::time::Duration;
1010
pub trait EpochBlockOracleSubgraph {
1111
fn supported_networks(self: Arc<Self>) -> Pin<Box<dyn Stream<Item = Result<String, Error>>>>;
1212
}
@@ -22,7 +22,10 @@ impl EpochBlockOracleSubgraphImpl {
2222
Arc::new(EpochBlockOracleSubgraphImpl {
2323
logger,
2424
endpoint,
25-
client: Client::new(),
25+
client: Client::builder()
26+
.timeout(Duration::from_secs(60))
27+
.build()
28+
.unwrap(),
2629
})
2730
}
2831
}

availability-oracle/src/ipfs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use bytes::Bytes;
33
use common::prelude::*;
44
use common::prometheus;
55
use moka::future::Cache;
6+
use reqwest::Client;
67
use std::time::Duration;
78
use tiny_cid::Cid;
89

@@ -25,7 +26,7 @@ pub trait Ipfs {
2526
pub struct IpfsImpl {
2627
endpoint: String,
2728
semaphore: tokio::sync::Semaphore,
28-
client: reqwest::Client,
29+
client: Client,
2930

3031
// Cache for CIDs; we invalidate this cache between runs to ensure we're checking
3132
// IPFS regularly
@@ -38,7 +39,7 @@ pub struct IpfsImpl {
3839
impl IpfsImpl {
3940
pub fn new(endpoint: String, max_concurrent: usize, timeout: Duration) -> Self {
4041
IpfsImpl {
41-
client: reqwest::Client::new(),
42+
client: Client::new(),
4243
endpoint,
4344
semaphore: tokio::sync::Semaphore::new(max_concurrent),
4445
cache: Cache::new(10000),

availability-oracle/src/network_subgraph.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use common::prelude::*;
33
use futures::stream;
44
use futures::Stream;
55
use multibase::Base;
6+
use reqwest::Client;
67
use serde_derive::{Deserialize, Serialize};
78
use std::collections::BTreeMap;
89
use std::pin::Pin;
@@ -39,15 +40,18 @@ pub trait NetworkSubgraph {
3940
pub struct NetworkSubgraphImpl {
4041
logger: Logger,
4142
endpoint: String,
42-
client: reqwest::Client,
43+
client: Client,
4344
}
4445

4546
impl NetworkSubgraphImpl {
4647
pub fn new(logger: Logger, endpoint: String) -> Arc<Self> {
4748
Arc::new(NetworkSubgraphImpl {
4849
logger,
4950
endpoint,
50-
client: reqwest::Client::new(),
51+
client: Client::builder()
52+
.timeout(Duration::from_secs(60))
53+
.build()
54+
.unwrap(),
5155
})
5256
}
5357
}

0 commit comments

Comments
 (0)