{"record":{"id":"34503640f8c3c752","repo":"tonhowtf/omniget","slug":"failed-to-connect-to-relay","errorCode":null,"errorMessage":"Failed to connect to relay {}: {}","messagePattern":"Failed to connect to relay (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/platforms/p2p.rs","lineNumber":30,"sourceCode":"\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);\n    }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/p2p.rs#L12-L48","documentation":"connect_relay() fails to establish a TCP connection to the P2P relay server within a 10-second timeout. The error wraps the underlying io::Error from TcpStream::connect. It is thrown by download() and run_sender() whenever the relay is unreachable.","triggerScenarios":"TcpStream::connect(&addr) returns an OS-level connect error (connection refused, unreachable host, DNS failure), or the connect does not complete within 10 seconds.","commonSituations":"Relay server is down or the port is firewalled; wrong relay host configured; corporate/ISP networks blocking non-HTTP TCP; IPv6 address attempted when only IPv4 works; relay overloaded.","solutions":["Verify the relay server is running and reachable (nc/telnet to the relay host:port)","Check local firewall/network rules allow outbound TCP to the relay port","Confirm the relay address the code resolves to is correct (DNS, config)","Retry later or deploy/fail over to another relay instance","Increase the 10s timeout if connecting from high-latency networks"],"exampleFix":"// before\nlet stream = connect_relay().await?;\n// after\nlet stream = match connect_relay().await {\n    Ok(s) => s,\n    Err(e) => {\n        tracing::error!(\"relay unreachable: {e:#}\");\n        anyhow::bail!(\"Relay unavailable, try again later\");\n    }\n};","handlingStrategy":"retry","validationCode":"use std::net::ToSocketAddrs;\nfn relay_reachable(addr: &str) -> bool {\n    addr.to_socket_addrs().map(|it| it.count() > 0).unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match connect_relay().await {\n    Ok(s) => s,\n    Err(e) => {\n        tracing::warn!(\"relay connect failed: {e:#}\");\n        tokio::time::sleep(Duration::from_secs(2)).await; // then retry, max 3\n        return Err(anyhow!(\"relay unavailable: {e}\"));\n    }\n}","preventionTips":["Health-check the relay before starting a transfer","Run transfers on networks that permit outbound TCP to the relay port","Keep a configurable relay address for failover","Set a retry budget with exponential backoff around connect_relay"],"tags":["network","tcp","p2p","timeout","tokio"],"backgroundTag":"connection-refused","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"}