From e2d3913ea63646c85572bd19fc7d4e584bfa3544 Mon Sep 17 00:00:00 2001 From: Martin Dyring-Andersen Date: Tue, 14 Nov 2023 19:54:58 +0100 Subject: [PATCH 1/2] rpc: Add HTTP timeout, default 30 seconds. Closes #1379. --- rpc/src/client/transport/http.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rpc/src/client/transport/http.rs b/rpc/src/client/transport/http.rs index d6d2135d3..a0349d3f5 100644 --- a/rpc/src/client/transport/http.rs +++ b/rpc/src/client/transport/http.rs @@ -7,6 +7,7 @@ use core::{ use async_trait::async_trait; use reqwest::{header, Proxy}; +use std::time::Duration; use tendermint::{block::Height, evidence::Evidence, Hash}; use tendermint_config::net; @@ -63,6 +64,7 @@ pub struct Builder { url: HttpClientUrl, compat: CompatMode, proxy_url: Option, + timeout: Duration, } impl Builder { @@ -85,9 +87,20 @@ impl Builder { self } + /// The timeout is applied from when the request starts connecting until + /// the response body has finished. + /// + /// The default is 30 seconds. + pub fn timeout(mut self, duration: Duration) -> Self { + self.timeout = duration; + self + } + /// Try to create a client with the options specified for this builder. pub fn build(self) -> Result { - let builder = reqwest::ClientBuilder::new().user_agent(USER_AGENT); + let builder = reqwest::ClientBuilder::new() + .user_agent(USER_AGENT) + .timeout(self.timeout); let inner = match self.proxy_url { None => builder.build().map_err(Error::http)?, Some(proxy_url) => { @@ -142,6 +155,7 @@ impl HttpClient { url, compat: Default::default(), proxy_url: None, + timeout: Duration::from_secs(30), } } From a65ca97d1cbac77e1712f045db206ee8da48d447 Mon Sep 17 00:00:00 2001 From: Martin Dyring-Andersen Date: Tue, 14 Nov 2023 21:30:34 +0100 Subject: [PATCH 2/2] Add .changelog entry --- .changelog/unreleased/improvements/1379-rpc-http-timeout.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/1379-rpc-http-timeout.md diff --git a/.changelog/unreleased/improvements/1379-rpc-http-timeout.md b/.changelog/unreleased/improvements/1379-rpc-http-timeout.md new file mode 100644 index 000000000..54495f50c --- /dev/null +++ b/.changelog/unreleased/improvements/1379-rpc-http-timeout.md @@ -0,0 +1,2 @@ +- Add request timeout for the RPC HttpClient + ([\#1379](https://github.com/informalsystems/tendermint-rs/issues/1379)) \ No newline at end of file