tonhowtf/omniget · info

Send cancelled while paused

Error message

Send cancelled while paused

What it means

In the P2P transfer sender loop (p2p.rs run_sender), while the session is paused the sender polls every 100ms and checks the shared CancellationToken. If cancellation fires during the pause, the sender aborts with this error instead of resuming reading the file. It exists so a cancelled send does not hang forever while paused.

Solutions

  1. Treat this as an expected abort: catch it and clean up the session/socket rather than retrying.
  2. If the send should continue, avoid cancelling while paused — resume the session first, then cancel if needed.
  3. Check cancel.is_cancelled() before pausing or before entering the loop so the state transition is handled explicitly.

Example fix

// before
loop {
    while session.paused.load(Ordering::Relaxed) {
        tokio::time::sleep(Duration::from_millis(100)).await;
    }
    ...
}
// after
// select on cancellation so pause and cancel are handled uniformly
tokio::select! {
    _ = cancel.cancelled() => anyhow::bail!("Send cancelled"),
    _ = async {
        while session.paused.load(Ordering::Relaxed) {
            tokio::time::sleep(Duration::from_millis(100)).await;
        }
    } => {}
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before sending
if cancel.is_cancelled() { return Err(anyhow!("Send cancelled")); }

Try / catch

match run_sender(...).await {
    Err(e) if e.to_string().contains("cancelled") => cleanup_session(&session),
    other => other?,
}

Prevention

When it happens

Trigger: Calling cancel on the transfer token while session.paused is true; e.g. the receiver disconnects or the user aborts a paused send via the cancellation token passed to run_sender.

Common situations: User pauses a P2P file send and then closes the app/cancels the transfer; peer triggers cancellation while the sender is parked in the pause-wait loop.

Related errors


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

Appendix: source

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

    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;
        if session.file_size > 0 {
            *session.progress.lock().await = (sent as f64 / session.file_size as f64) * 100.0;
        }
    }

    write_half.flush().await?;

View on GitHub (pinned to 8600b91f42)