fix: ping every 5min (was 5s), clean endpoint on failure, never block connect
Some checks failed
Mirror to GitHub / mirror (push) Failing after 39s
Build Release Binaries / build-amd64 (push) Failing after 3m45s

- Ping interval: 5 minutes (was 5 seconds — too aggressive)
- Rust ping_relay: explicitly close endpoint + shutdown runtime on failure
- Connect button works regardless of ping status (never blocked)
- Ping failure doesn't corrupt engine state

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-07 11:40:14 +04:00
parent 7973c8c6a3
commit 68b56d9172
2 changed files with 16 additions and 8 deletions

View File

@@ -90,12 +90,13 @@ fun InCallScreen(
var showManageRelays by remember { mutableStateOf(false) } var showManageRelays by remember { mutableStateOf(false) }
// Periodic ping every 5 seconds while app is open // Ping once on launch, then every 5 minutes
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
viewModel.loadSavedFingerprints() viewModel.loadSavedFingerprints()
while (true) {
viewModel.pingAllServers() viewModel.pingAllServers()
kotlinx.coroutines.delay(5000) while (true) {
kotlinx.coroutines.delay(300_000) // 5 minutes
viewModel.pingAllServers()
} }
} }

View File

@@ -177,19 +177,22 @@ impl WzpEngine {
.enable_all() .enable_all()
.build()?; .build()?;
rt.block_on(async { let result = rt.block_on(async {
let bind: SocketAddr = "0.0.0.0:0".parse().unwrap(); let bind: SocketAddr = "0.0.0.0:0".parse().unwrap();
let endpoint = wzp_transport::create_endpoint(bind, None)?; let endpoint = wzp_transport::create_endpoint(bind, None)?;
let client_cfg = wzp_transport::client_config(); let client_cfg = wzp_transport::client_config();
let start = Instant::now(); let start = Instant::now();
let conn = tokio::time::timeout( let conn_result = tokio::time::timeout(
std::time::Duration::from_secs(3), std::time::Duration::from_secs(3),
wzp_transport::connect(&endpoint, addr, "ping", client_cfg), wzp_transport::connect(&endpoint, addr, "ping", client_cfg),
) )
.await .await;
.map_err(|_| anyhow::anyhow!("timeout"))??;
// Always close endpoint to prevent resource leaks
endpoint.close(0u32.into(), b"done");
let conn = conn_result.map_err(|_| anyhow::anyhow!("timeout"))??;
let rtt_ms = start.elapsed().as_millis() as u64; let rtt_ms = start.elapsed().as_millis() as u64;
let server_fp = conn let server_fp = conn
.peer_identity() .peer_identity()
@@ -203,8 +206,12 @@ impl WzpEngine {
.unwrap_or_default(); .unwrap_or_default();
conn.close(0u32.into(), b"ping"); conn.close(0u32.into(), b"ping");
Ok(format!(r#"{{"rtt_ms":{},"server_fingerprint":"{}"}}"#, rtt_ms, server_fp)) Ok::<_, anyhow::Error>(format!(r#"{{"rtt_ms":{},"server_fingerprint":"{}"}}"#, rtt_ms, server_fp))
}) });
// Shutdown runtime cleanly with timeout
rt.shutdown_timeout(std::time::Duration::from_millis(500));
result
} }
pub fn set_mute(&self, muted: bool) { pub fn set_mute(&self, muted: bool) {