tonhowtf/omniget · info

Send cancelled during transfer

Error message

Send cancelled during transfer

What it means

At the top of each transfer loop iteration run_sender checks cancel.is_cancelled(); once the token fires mid-transfer it bails with "Send cancelled during transfer", stopping the file stream. Intentional cancellation, not a data or network failure.

Solutions

  1. Expected behavior — catch it, set session status to cancelled, and inform the receiver side so it can clean up.
  2. If it fires unexpectedly, look for stray cancel_token.clone() holders or timeout wrappers around the transfer.
  3. Remember there is no resume; restart the whole send if the transfer must complete.

Example fix

// before
run_sender(session).await?; // cancelled error bubbles as failure
// after
if let Err(e) = run_sender(session).await {
    if e.to_string().contains("Send cancelled") { ui.mark_cancelled(&session.id); }
    else { return Err(e); }
}
Defensive patterns

Strategy: try-catch

Try / catch

match run_sender(session.clone(), cancel.clone()).await {
    Err(e) if e.to_string().contains("Send cancelled during transfer") => {
        session.status.lock().await = "cancelled".into();
        ui.mark_transfer_stopped(&session.id);
    }
    other => other?,
}

Prevention

When it happens

Trigger: cancel_token.cancel() while the loop is actively reading the file and writing chunks (status == "transferring").

Common situations: User hits stop mid-transfer; UI cancels on window close; a new send session replaces a stale one and cancels the old token.

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/f80d95078198069e. Report an issue: GitHub.

Appendix: source

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

    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;

    loop {
        if cancel.is_cancelled() {
            anyhow::bail!("Send cancelled during transfer");
        }

        while session.paused.load(std::sync::atomic::Ordering::Relaxed) {
            tokio::time::sleep(std::time::Duration::from_millis(100)).await;
            if cancel.is_cancelled() {
                anyhow::bail!("Send cancelled while paused");
            }
        }

        let n = file.read(&mut buf).await?;
        if n == 0 {
            break;
        }

        write_half.write_all(&buf[..n]).await?;
        sent += n as u64;

        *session.sent_bytes.lock().await = sent;

View on GitHub (pinned to 8600b91f42)