tonhowtf/omniget · info

Send cancelled while waiting for OK

Error message

Send cancelled while waiting for OK

What it means

After sending the file name/size header, the sender waits for the receiver's acceptance line via tokio::select!; if cancel.cancelled() wins the race before the OK arrives, run_sender bails with "Send cancelled while waiting for OK". Cooperative cancellation during the consent phase.

Solutions

  1. Treat as expected control flow — mark the session cancelled and close the socket.
  2. If unexpected, audit token clones and UI timeout logic that may cancel too aggressively.
  3. Surface a distinct UI state ('cancelled before accept') so users know the transfer never started.

Example fix

// before
run_sender(session).await?;
// after
if let Err(e) = run_sender(session).await {
    if e.to_string().contains("cancelled") { session.status.lock().await = "cancelled".into(); }
    else { return Err(e); }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if cancel.is_cancelled() { anyhow::bail!("Session already cancelled"); }

Try / catch

match run_sender(session.clone(), cancel.clone()).await {
    Err(e) if e.to_string().contains("cancelled while waiting for OK") => {
        session.status.lock().await = "cancelled-before-accept".into();
    }
    other => other?,
}

Prevention

When it happens

Trigger: cancel_token.cancel() is called while the sender is blocked awaiting the receiver's OK/OK-response after transmitting the header.

Common situations: User cancels while the receiver is still looking at the accept prompt; UI-level timeout cancels the session; app shutdown.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

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

        }
    };

    check_relay_error(&ready)?;
    if ready != "READY" {
        anyhow::bail!("Unexpected relay response: {}", ready);
    }

    *session.status.lock().await = "connected".to_string();
    tracing::info!("[p2p] receiver connected");

    let header = format!("{}\n{}\n", session.file_name, session.file_size);
    write_half.write_all(header.as_bytes()).await?;
    write_half.flush().await?;

    let ok_response = tokio::select! {
        line = read_line(&mut reader) => line?,
        _ = cancel.cancelled() => {
            anyhow::bail!("Send cancelled while waiting for OK");
        }
    };

    if ok_response != "OK" {
        anyhow::bail!("Receiver rejected transfer: {}", ok_response);
    }

    *session.status.lock().await = "transferring".to_string();
    tracing::info!(
        "[p2p] transferring: {} ({} bytes)",
        session.file_name,
        session.file_size
    );

    let mut file = File::open(&session.file_path).await?;
    let mut buf = vec![0u8; CHUNK_SIZE];
    let mut sent: u64 = 0;

View on GitHub (pinned to 8600b91f42)