tonhowtf/omniget · error
Failed to connect to relay
Error message
Failed to connect to relay {}: {} What it means
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.
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
Example fix
// before
let stream = connect_relay().await?;
// after
let stream = match connect_relay().await {
Ok(s) => s,
Err(e) => {
tracing::error!("relay unreachable: {e:#}");
anyhow::bail!("Relay unavailable, try again later");
}
}; Defensive patterns
Strategy: retry
Validate before calling
use std::net::ToSocketAddrs;
fn relay_reachable(addr: &str) -> bool {
addr.to_socket_addrs().map(|it| it.count() > 0).unwrap_or(false)
} Try / catch
match connect_relay().await {
Ok(s) => s,
Err(e) => {
tracing::warn!("relay connect failed: {e:#}");
tokio::time::sleep(Duration::from_secs(2)).await; // then retry, max 3
return Err(anyhow!("relay unavailable: {e}"));
}
} Prevention
- 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
When it happens
Trigger: TcpStream::connect(&addr) returns an OS-level connect error (connection refused, unreachable host, DNS failure), or the connect does not complete within 10 seconds.
Common situations: 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.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- Connection to relay timed out (10s)
- Connection to relay timed out (10s)
- Relay closed connection unexpectedly
- Relay closed connection unexpectedly
- Failed to connect to relay
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/34503640f8c3c752.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:30
use crate::models::media::{DownloadOptions, DownloadResult, MediaInfo, MediaType, VideoQuality};
use crate::platforms::traits::PlatformDownloader;
const CHUNK_SIZE: usize = 64 * 1024;
fn relay_addr() -> String {
std::env::var("OMNIGET_RELAY").unwrap_or_else(|_| "relay.tonho.wtf:9009".to_string())
}
async fn connect_relay() -> anyhow::Result<TcpStream> {
let addr = relay_addr();
let stream = tokio::time::timeout(
std::time::Duration::from_secs(10),
TcpStream::connect(&addr),
)
.await
.map_err(|_| anyhow!("Connection to relay timed out (10s)"))?
.map_err(|e| anyhow!("Failed to connect to relay {}: {}", addr, e))?;
Ok(stream)
}
async fn read_line(
reader: &mut BufReader<tokio::io::ReadHalf<TcpStream>>,
) -> anyhow::Result<String> {
let mut line = String::new();
let n = reader.read_line(&mut line).await?;
if n == 0 {
anyhow::bail!("Relay closed connection unexpectedly");
}
Ok(line.trim_end().to_string())
}
fn check_relay_error(line: &str) -> anyhow::Result<()> {
if let Some(err) = line.strip_prefix("ERROR ") {
anyhow::bail!("Relay error: {}", err);
}View on GitHub (pinned to 8600b91f42)