tonhowtf/omniget · info
Download cancelled during session creation
Error message
Download cancelled during session creation
What it means
During download() the torrent session (librqbit Session) is created lazily and cached; creation races against the cancellation token. If cancellation fires before the session finishes initializing, the select! arm picks cancelled() and bails with this error. It is a normal, expected abort path, not a fault.
Solutions
- No fix needed — this is the intended cancellation path; propagate the error as Cancelled
- In the caller, match on the error message/cancellation state and treat it as success-abort rather than failure
- Ensure the cancellation token isn't cancelled prematurely by an overly eager timeout or UI handler
Example fix
// before
match download(...).await { Err(e) => report_error(e), ... }
// after
match download(...).await {
Err(e) if e.to_string().contains("cancelled") => tracing::info!("user cancelled"),
Err(e) => report_error(e),
Ok(r) => handle(r),
} Defensive patterns
Strategy: try-catch
Try / catch
match download(...).await {
Err(e) if format!("{e:#}").contains("cancelled") => info!("download aborted by user"),
Err(e) => error!("download failed: {e:#}"),
Ok(r) => handle(r),
} Prevention
- Use a typed Cancelled error instead of string matching
- Only cancel the token when the user explicitly aborts
When it happens
Trigger: The user (or caller) cancels the download (CancellationToken cancelled) while the first-time session initialization is still in flight in the tokio::select! between session creation and cancel_rx.cancelled().
Common situations: User closes a dialog or hits stop while the torrent engine is starting up; app shutdown during first download; timeouts cancelling slow disk-heavy session init.
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
- Download cancelled
- Download cancelled by user
- Send cancelled while waiting for receiver
- Send cancelled while paused
- Download cancelled
AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12).
Data as JSON: /api/errors/06509066bec31aa5.
Report an issue: GitHub.
Appendix: source
Thrown at src-tauri/src/platforms/magnet/mod.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)