fix: ping every 5min (was 5s), clean endpoint on failure, never block connect
- 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:
@@ -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()
|
||||||
|
viewModel.pingAllServers()
|
||||||
while (true) {
|
while (true) {
|
||||||
|
kotlinx.coroutines.delay(300_000) // 5 minutes
|
||||||
viewModel.pingAllServers()
|
viewModel.pingAllServers()
|
||||||
kotlinx.coroutines.delay(5000)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user