From 89bbaac4f14ae84185c7eac636a886e8bef6a25e Mon Sep 17 00:00:00 2001 From: Rafael Cardenas Date: Mon, 9 Sep 2024 20:35:01 -0600 Subject: [PATCH] fix: add a max timeout for outgoing requests --- components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs | 3 ++- components/chainhook-sdk/src/chainhooks/stacks/mod.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs b/components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs index 7d49ec127..633f310ad 100644 --- a/components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs +++ b/components/chainhook-sdk/src/chainhooks/bitcoin/mod.rs @@ -21,7 +21,7 @@ use serde::{de, Deserialize, Deserializer}; use serde_json::Value as JsonValue; use std::{ collections::{BTreeMap, HashMap, HashSet}, - str::FromStr, + str::FromStr, time::Duration, }; use reqwest::RequestBuilder; @@ -766,6 +766,7 @@ pub fn handle_bitcoin_hook_action<'a>( match &trigger.chainhook.action { HookAction::HttpPost(http) => { let client = Client::builder() + .timeout(Duration::from_secs(30)) .build() .map_err(|e| format!("unable to build http client: {}", e.to_string()))?; let host = format!("{}", http.url); diff --git a/components/chainhook-sdk/src/chainhooks/stacks/mod.rs b/components/chainhook-sdk/src/chainhooks/stacks/mod.rs index 6bad60849..b3fe0334f 100644 --- a/components/chainhook-sdk/src/chainhooks/stacks/mod.rs +++ b/components/chainhook-sdk/src/chainhooks/stacks/mod.rs @@ -22,6 +22,7 @@ use schemars::JsonSchema; use serde_json::Value as JsonValue; use std::collections::{BTreeMap, HashMap}; use std::io::Cursor; +use std::time::Duration; use reqwest::RequestBuilder; @@ -1337,6 +1338,7 @@ pub fn handle_stacks_hook_action<'a>( match &trigger.chainhook.action { HookAction::HttpPost(http) => { let client = Client::builder() + .timeout(Duration::from_secs(30)) .build() .map_err(|e| format!("unable to build http client: {}", e.to_string()))?; let host = format!("{}", http.url);