From fe805cce14f354a86cc9063631ddfef8eb4bb295 Mon Sep 17 00:00:00 2001 From: willamhou Date: Sun, 15 Mar 2026 19:25:54 +0800 Subject: [PATCH] perf(tunnel): reuse HTTP client in CustomTunnel health checks Previously, `health_check()` created a new `reqwest::Client` on every call. Since health checks run periodically, this caused unnecessary TLS session setup and connection pool churn. Store a shared client on the struct instead, created once in the constructor with a 5s timeout. Fixes #1039 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- src/tunnel/custom.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tunnel/custom.rs b/src/tunnel/custom.rs index 9a2be403..81211da8 100644 --- a/src/tunnel/custom.rs +++ b/src/tunnel/custom.rs @@ -27,6 +27,7 @@ pub struct CustomTunnel { url_pattern: Option, proc: SharedProcess, url: SharedUrl, + http_client: reqwest::Client, } impl CustomTunnel { @@ -41,6 +42,10 @@ impl CustomTunnel { url_pattern, proc: new_shared_process(), url: new_shared_url(), + http_client: reqwest::Client::builder() + .timeout(std::time::Duration::from_secs(5)) + .build() + .unwrap_or_else(|_| reqwest::Client::new()), } } } @@ -140,9 +145,9 @@ impl Tunnel for CustomTunnel { async fn health_check(&self) -> bool { if let Some(ref url) = self.health_url { - return reqwest::Client::new() + return self + .http_client .get(url) - .timeout(std::time::Duration::from_secs(5)) .send() .await .is_ok();