tonhowtf/omniget · info

Send cancelled during transfer

Error message

Send cancelled during transfer

What it means

During the byte-transfer loop in run_sender, the cancel token is polled every iteration; if it fires, the send aborts with this error. Like the other cancellation errors, it signals a deliberate abort (including cancel-during-pause) rather than a transport failure. The receiver will see the connection drop mid-stream.

Solutions

  1. Treat as a user-intended abort: match on the message and mark the session cancelled rather than failed
  2. For resumable sends, record the bytes-sent offset before cancelling and implement range-resume on a new session
  3. Always drain/notify so the receiver's partial file can be cleaned up (mirror the receiver's remove_file behavior)

Example fix

// before
if cancel.is_cancelled() {
    anyhow::bail!("Send cancelled during transfer");
}
// after
if cancel.is_cancelled() {
    *session.status.lock().await = "cancelled".to_string();
    tracing::info!("[p2p] cancelled after {} of {} bytes", sent, session.file_size);
    anyhow::bail!("Send cancelled during transfer");
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Only cancel mid-transfer for explicit user stop
if cancel.is_cancelled() {
    anyhow::bail!("Not starting transfer: token already cancelled");
}

Try / catch

if let Err(e) = run_sender(&mut session, &cancel).await {
    if e.to_string().contains("Send cancelled") {
        session.status.lock().await = "cancelled".into();
        tracing::info!("[p2p] send aborted by user");
    } else {
        return Err(e);
    }
}

Prevention

When it happens

Trigger: Cancelling the CancellationToken while run_sender is actively writing file bytes (or while it is parked in the paused busy-wait loop — that path raises "Send cancelled while paused" from the same phase).

Common situations: User stops a large mid-flight transfer; app shutdown during a long send; a supervisor cancels stalled or paused sessions.

Related errors


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

Appendix: source

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

    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)