tonhowtf/omniget · error

Unexpected relay response

Error message

Unexpected relay response: {}

What it means

After the receiver connects through the relay, it reads one line and expects exactly "READY"; anything else means the relay/sender is not in the expected state. check_relay_error() runs first, so this fires only for non-error responses that are not READY — a protocol desynchronization between relay versions or a corrupted/short response.

Solutions

  1. Verify the relay server protocol matches the client (both expect sender->WAIT, receiver->READY)
  2. Re-generate the P2P code and retry — stale/expired codes cause off-protocol responses
  3. Log the raw response line and add handling for known alternate states (e.g. retry on "WAIT" with backoff)

Example fix

// before
if response != "READY" {
    anyhow::bail!("Unexpected relay response: {}", response);
}
// after
match response.as_str() {
    "READY" => {}
    "WAIT" => anyhow::bail!("Sender not ready yet; retry the connection"),
    other => anyhow::bail!("Unexpected relay response: {}", other),
}
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight: confirm the relay is reachable and protocol-compatible
let probe = tokio::net::TcpStream::connect(&relay_addr).await;
if probe.is_err() { anyhow::bail!("Relay unreachable: {}", relay_addr); }

Try / catch

match p2p::download(&info, &opts, tx).await {
    Err(e) if e.to_string().contains("Unexpected relay response") => {
        tracing::warn!("relay handshake mismatch, regenerating code and retrying");
        // regenerate code, retry once
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling download() and reaching the relay handshake where the relay responds with a line other than "READY" after check_relay_error passes — e.g. an unexpected "WAIT", empty line, or a mismatched relay protocol version.

Common situations: Receiver connecting before the sender finished registration; relay server version older/newer than the client expects; network proxy mangling the handshake line; stale relay code reused after the session ended.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/p2p.rs:133

            .ok_or_else(|| anyhow!("Invalid P2P URL"))?;

        let _ = progress.send(ProgressUpdate::percent(-2.0)).await;

        tracing::info!("[p2p] connecting to relay for code: {}", code);

        let stream = connect_relay().await?;
        let (read_half, mut write_half) = tokio::io::split(stream);
        let mut reader = BufReader::new(read_half);

        write_half
            .write_all(format!("RECV {}\n", code).as_bytes())
            .await?;
        write_half.flush().await?;

        let response = read_line(&mut reader).await?;
        check_relay_error(&response)?;
        if response != "READY" {
            anyhow::bail!("Unexpected relay response: {}", response);
        }

        tracing::info!("[p2p] connected to sender via relay");

        let file_name = read_line(&mut reader).await?;
        let file_size_str = read_line(&mut reader).await?;
        let file_size: u64 = file_size_str
            .parse()
            .map_err(|_| anyhow!("Invalid file size from sender: {}", file_size_str))?;

        tracing::info!("[p2p] receiving: {} ({} bytes)", file_name, file_size);

        write_half.write_all(b"OK\n").await?;
        write_half.flush().await?;

        let _ = progress.send(ProgressUpdate::percent(0.0)).await;

        let sanitized = sanitize_filename::sanitize(&file_name);

View on GitHub (pinned to 8600b91f42)