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 <[email protected]>
Co-Authored-By: Happy <[email protected]>
This commit is contained in:
willamhou
2026-03-22 19:49:11 -07:00
committed by Zaki
co-authored by Claude Happy
parent abba083147
commit fe805cce14
+7 -2
View File
@@ -27,6 +27,7 @@ pub struct CustomTunnel {
url_pattern: Option<String>,
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();