tonhowtf/omniget · info

Download cancelled during session creation

Error message

Download cancelled during session creation

What it means

magnet.rs throws this when the download is cancelled while the librqbit torrent session is being created. Session creation races against the cancel token via tokio::select; if cancel_rx fires first, the code bails with 'Download cancelled during session creation'. It is an expected cancellation path, not a torrent failure.

Solutions

  1. Treat this message as a normal cancellation outcome: catch it and skip reporting an error to the user.
  2. If cancellation was unintended, check what fired cancel_rx (UI cancel, timeout, shutdown) before the session finished initializing.
  3. Distinguish it from 'Failed to initialize torrent session' when handling — the latter indicates a real librqbit error, this one does not.
  4. Consider making the library return a typed Cancelled enum variant instead of string matching on the error message.
Defensive patterns

Strategy: try-catch

Validate before calling

// check before starting
cancel_rx.is_cancelled(),
// if true, don't call download at all

Try / catch

match download(...).await {
    Err(e) if e.to_string().contains("cancelled") => {
        info!("cancelled during init; skipping");
    }
    Err(e) => report_error(e),
    Ok(r) => handle(r),
}

Prevention

When it happens

Trigger: tokio::select! branch `_ = cancel_rx.cancelled()` wins while awaiting session initialization (the result branch would have mapped errors to 'Failed to initialize torrent session'); raised at magnet.rs:156.

Common situations: User cancels right after starting a magnet download, before the session is ready; slow session init (large magnet, slow DHT bootstrap) gives the cancel window; app shutdown during startup of the first torrent.

Related errors


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

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/magnet.rs:156

                                    e
                                );
                                match Session::new_with_opts(output_pb.clone(), make_opts(true, false)).await {
                                    Ok(s) => Ok(s),
                                    Err(e2) => {
                                        tracing::warn!(
                                            "[magnet] DHT init failed ({}); retrying with DHT disabled (trackers/PEX only)",
                                            e2
                                        );
                                        Session::new_with_opts(output_pb, make_opts(true, true)).await
                                    }
                                }
                            }
                        }
                    } => {
                        result.map_err(|e| anyhow::anyhow!("Failed to initialize torrent session: {}", e))?
                    }
                    _ = cancel_rx.cancelled() => {
                        anyhow::bail!("Download cancelled during session creation");
                    }
                };
                *guard = Some(s.clone());
                *dir_guard = Some(output_dir.clone());
                s
            } else {
                tracing::info!("[magnet] reusing existing session");
                guard.as_ref().unwrap().clone()
            }
        };

        let add_torrent = if url.starts_with("magnet:")
            || url.starts_with("http://")
            || url.starts_with("https://")
        {
            AddTorrent::from_url(url)
        } else {
            let path = std::path::Path::new(url);

View on GitHub (pinned to 8600b91f42)