Repository: informalsystems/tendermint-rs (language: rust)

Issue:
rpc: Introduce HTTP timeouts
### Description
Add configurable timeout that is passed to reqwest. The current default is "no timeout", which can lead to requests never finishing.
<!--

Please describe the enhancement you would like to see implemented in
tendermint-rs. Give as much context as possible.

-->

### Definition of "done"
Add timeout() to request builder and wire it into reqwest.
<!--

Please describe clear and practical acceptance criteria for this issue. Anyone
in the team should be able to look at this issue and determine whether or not
the new feature/enhancement has been implemented, and therefore whether or not
this issue can be closed.

-->



Discussion / hints:

Fix patch:
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
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<HttpClientUrl>,
+    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<HttpClient, Error> {
-        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),
         }
     }
 


Test patch: