tonhowtf/omniget · error

Connection to relay timed out (10s)

Error message

Connection to relay timed out (10s)

What it means

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.

Solutions

  1. Verify the relay server is running and reachable (ping/Telnet the relay host:port used by relay_addr()).
  2. Check local network/firewall rules that may block the relay port and allow outbound TCP to it.
  3. Increase the 10s timeout constant if the relay is known to be slow to accept connections.
  4. Confirm relay_addr() returns the correct host:port (stale or misconfigured relay address is a common cause).
  5. Implement retry with backoff in connect_relay for transient network issues.

Example fix

// before
let stream = tokio::time::timeout(
    std::time::Duration::from_secs(10),
    TcpStream::connect(&addr),
)
.await
.map_err(|_| anyhow!("Connection to relay timed out (10s)"))??;
// after
let stream = tokio::time::timeout(
    std::time::Duration::from_secs(30),
    TcpStream::connect(&addr),
)
.await
.map_err(|_| anyhow!("Connection to relay timed out after 30s; check relay {} reachability", addr))??;
Defensive patterns

Strategy: retry

Validate before calling

// Rust: pre-check relay reachability before download
async fn relay_reachable(addr: &str) -> bool {
    tokio::net::TcpStream::connect(addr).await.is_ok()
}

Try / catch

match connect_relay().await {
    Ok(stream) => stream,
    Err(e) if e.to_string().contains("timed out") => {
        // retry with backoff, then surface user-facing 'relay unreachable'
        tokio::time::sleep(Duration::from_secs(2)).await;
        connect_relay().await?
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/4d68a13b34f2d73c. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/src/platforms/p2p/mod.rs:31

use tokio_util::sync::CancellationToken;

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)