Skip to content

Commit

Permalink
Log warning if a Web3 request timed out
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyboyko0791 committed Oct 28, 2021
1 parent f5752f8 commit 246e565
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions mm2src/coins/eth/web3_transport.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{RpcTransportEventHandler, RpcTransportEventHandlerShared};
use common::log::warn;
#[cfg(not(target_arch = "wasm32"))] use futures::FutureExt;
use futures::TryFutureExt;
use futures01::{Future, Poll};
Expand All @@ -11,6 +12,8 @@ use web3::error::{Error, ErrorKind};
use web3::helpers::{build_request, to_result_from_output, to_string};
use web3::{RequestId, Transport};

const REQUEST_TIMEOUT_S: f64 = 60.;

/// Parse bytes RPC response into `Result`.
/// Implementation copied from Web3 HTTP transport
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -122,13 +125,15 @@ async fn send_request(
*req.uri_mut() = uri.clone();
req.headers_mut()
.insert(http::header::CONTENT_TYPE, HeaderValue::from_static("application/json"));
let timeout = Timer::sleep(60.);
let timeout = Timer::sleep(REQUEST_TIMEOUT_S);
let req = Box::pin(slurp_req(req));
let rc = select(req, timeout).await;
let res = match rc {
Either::Left((r, _t)) => r,
Either::Right((_t, _r)) => {
errors.push(ERRL!("Error requesting '{}': timeout", uri));
let error = ERRL!("Error requesting '{}': {}s timeout expired", uri, REQUEST_TIMEOUT_S);
warn!("{}", error);
errors.push(error);
continue;
},
};
Expand Down

0 comments on commit 246e565

Please sign in to comment.