From f7ccb67b0248403c2b2e202a48ba028ecc0fd595 Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Tue, 7 Apr 2026 15:00:32 +0400 Subject: [PATCH] fix: desktop ping closes endpoint properly, prevents resource leaks Co-Authored-By: Claude Opus 4.6 (1M context) --- desktop/src-tauri/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 5e1dc4b..7a31f0d 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -55,16 +55,19 @@ async fn ping_relay(relay: String) -> Result { let client_cfg = wzp_transport::client_config(); let start = std::time::Instant::now(); - match tokio::time::timeout( + let conn_result = tokio::time::timeout( std::time::Duration::from_secs(3), wzp_transport::connect(&endpoint, addr, "ping", client_cfg), ) - .await - { + .await; + + // Always close endpoint to prevent resource leaks + endpoint.close(0u32.into(), b"done"); + + match conn_result { Ok(Ok(conn)) => { let rtt_ms = start.elapsed().as_millis() as u32; - // Extract server fingerprint from peer certificate let server_fingerprint = conn .peer_identity() .and_then(|id| id.downcast::>().ok()) @@ -76,7 +79,6 @@ async fn ping_relay(relay: String) -> Result { format!("{h:016x}") })) .unwrap_or_else(|| { - // Fallback: hash the remote address as identifier format!("{:x}", addr.ip().to_string().len() as u64 * 0x9e3779b97f4a7c15 + addr.port() as u64) });