{"record":{"id":"275b847f8bba175e","repo":"tonhowtf/omniget","slug":"download-cancelled-during-session-creation","errorCode":null,"errorMessage":"Download cancelled during session creation","messagePattern":"Download cancelled during session creation","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src-tauri/omniget-core/src/platforms/magnet.rs","lineNumber":156,"sourceCode":"                                    e\n                                );\n                                match Session::new_with_opts(output_pb.clone(), make_opts(true, false)).await {\n                                    Ok(s) => Ok(s),\n                                    Err(e2) => {\n                                        tracing::warn!(\n                                            \"[magnet] DHT init failed ({}); retrying with DHT disabled (trackers/PEX only)\",\n                                            e2\n                                        );\n                                        Session::new_with_opts(output_pb, make_opts(true, true)).await\n                                    }\n                                }\n                            }\n                        }\n                    } => {\n                        result.map_err(|e| anyhow::anyhow!(\"Failed to initialize torrent session: {}\", e))?\n                    }\n                    _ = cancel_rx.cancelled() => {\n                        anyhow::bail!(\"Download cancelled during session creation\");\n                    }\n                };\n                *guard = Some(s.clone());\n                *dir_guard = Some(output_dir.clone());\n                s\n            } else {\n                tracing::info!(\"[magnet] reusing existing session\");\n                guard.as_ref().unwrap().clone()\n            }\n        };\n\n        let add_torrent = if url.starts_with(\"magnet:\")\n            || url.starts_with(\"http://\")\n            || url.starts_with(\"https://\")\n        {\n            AddTorrent::from_url(url)\n        } else {\n            let path = std::path::Path::new(url);","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/platforms/magnet.rs#L138-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Treat this message as a normal cancellation outcome: catch it and skip reporting an error to the user.","If cancellation was unintended, check what fired cancel_rx (UI cancel, timeout, shutdown) before the session finished initializing.","Distinguish it from 'Failed to initialize torrent session' when handling — the latter indicates a real librqbit error, this one does not.","Consider making the library return a typed Cancelled enum variant instead of string matching on the error message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check before starting\ncancel_rx.is_cancelled(),\n// if true, don't call download at all","typeGuard":null,"tryCatchPattern":"match download(...).await {\n    Err(e) if e.to_string().contains(\"cancelled\") => {\n        info!(\"cancelled during init; skipping\");\n    }\n    Err(e) => report_error(e),\n    Ok(r) => handle(r),\n}","preventionTips":["Don't cancel downloads during their initialization window unless shutdown is intended","Fast-fail cancelled requests before session creation","Distinguish 'cancelled' errors from real torrent init failures when logging"],"tags":["cancel","torrent","magnet","race-condition"],"backgroundTag":"operation-cancelled","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}