{"record":{"id":"4d68a13b34f2d73c","repo":"tonhowtf/omniget","slug":"connection-to-relay-timed-out-10s-mod","errorCode":null,"errorMessage":"Connection to relay timed out (10s)","messagePattern":"Connection to relay timed out \\(10s\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/platforms/p2p/mod.rs","lineNumber":31,"sourceCode":"use tokio_util::sync::CancellationToken;\n\nuse crate::models::media::{DownloadOptions, DownloadResult, MediaInfo, MediaType, VideoQuality};\nuse crate::platforms::traits::PlatformDownloader;\n\nconst CHUNK_SIZE: usize = 64 * 1024;\n\nfn relay_addr() -> String {\n    std::env::var(\"OMNIGET_RELAY\").unwrap_or_else(|_| \"relay.tonho.wtf:9009\".to_string())\n}\n\nasync fn connect_relay() -> anyhow::Result<TcpStream> {\n    let addr = relay_addr();\n    let stream = tokio::time::timeout(\n        std::time::Duration::from_secs(10),\n        TcpStream::connect(&addr),\n    )\n    .await\n    .map_err(|_| anyhow!(\"Connection to relay timed out (10s)\"))?\n    .map_err(|e| anyhow!(\"Failed to connect to relay {}: {}\", addr, e))?;\n    Ok(stream)\n}\n\nasync fn read_line(\n    reader: &mut BufReader<tokio::io::ReadHalf<TcpStream>>,\n) -> anyhow::Result<String> {\n    let mut line = String::new();\n    let n = reader.read_line(&mut line).await?;\n    if n == 0 {\n        anyhow::bail!(\"Relay closed connection unexpectedly\");\n    }\n    Ok(line.trim_end().to_string())\n}\n\nfn check_relay_error(line: &str) -> anyhow::Result<()> {\n    if let Some(err) = line.strip_prefix(\"ERROR \") {\n        anyhow::bail!(\"Relay error: {}\", err);","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/p2p/mod.rs#L13-L49","documentation":"connect_relay wraps the TCP connection to the relay server in a 10-second tokio timeout. If TcpStream::connect has not completed within 10s, the timeout elapses and this anyhow error is returned. It indicates the relay host did not accept (or even reject) the connection in time — typically an unreachable or overloaded relay.","triggerScenarios":"download or run_sender calls connect_relay() and the TcpStream::connect(&addr) future does not resolve within std::time::Duration::from_secs(10); the relay address is unreachable, firewalled, or the network is slow/down.","commonSituations":"Relay server is offline or behind a firewall dropping SYN packets; wrong relay address configured in relay_addr(); user's network blocks the relay port (corporate/ISP firewall); IPv6/IPv4 misrouting causing long connect hangs.","solutions":["Verify the relay server is running and reachable (ping/Telnet the relay host:port used by relay_addr()).","Check local network/firewall rules that may block the relay port and allow outbound TCP to it.","Increase the 10s timeout constant if the relay is known to be slow to accept connections.","Confirm relay_addr() returns the correct host:port (stale or misconfigured relay address is a common cause).","Implement retry with backoff in connect_relay for transient network issues."],"exampleFix":"// before\nlet stream = tokio::time::timeout(\n    std::time::Duration::from_secs(10),\n    TcpStream::connect(&addr),\n)\n.await\n.map_err(|_| anyhow!(\"Connection to relay timed out (10s)\"))??;\n// after\nlet stream = tokio::time::timeout(\n    std::time::Duration::from_secs(30),\n    TcpStream::connect(&addr),\n)\n.await\n.map_err(|_| anyhow!(\"Connection to relay timed out after 30s; check relay {} reachability\", addr))??;","handlingStrategy":"retry","validationCode":"// Rust: pre-check relay reachability before download\nasync fn relay_reachable(addr: &str) -> bool {\n    tokio::net::TcpStream::connect(addr).await.is_ok()\n}","typeGuard":null,"tryCatchPattern":"match connect_relay().await {\n    Ok(stream) => stream,\n    Err(e) if e.to_string().contains(\"timed out\") => {\n        // retry with backoff, then surface user-facing 'relay unreachable'\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        connect_relay().await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Monitor relay server uptime and alert on outages","Keep the 10s timeout generous but finite; document it","Cache the last-known-good relay address","Test P2P flows behind restrictive firewalls before release"],"tags":["network","timeout","tcp","p2p"],"backgroundTag":"request-timeout","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}