{"record":{"id":"06509066bec31aa5","repo":"tonhowtf/omniget","slug":"download-cancelled-during-session-creation-mod","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/src/platforms/magnet/mod.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/src/platforms/magnet/mod.rs#L138-L174","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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"],"exampleFix":"// before\nmatch download(...).await { Err(e) => report_error(e), ... }\n// after\nmatch download(...).await {\n    Err(e) if e.to_string().contains(\"cancelled\") => tracing::info!(\"user cancelled\"),\n    Err(e) => report_error(e),\n    Ok(r) => handle(r),\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match download(...).await {\n    Err(e) if format!(\"{e:#}\").contains(\"cancelled\") => info!(\"download aborted by user\"),\n    Err(e) => error!(\"download failed: {e:#}\"),\n    Ok(r) => handle(r),\n}","preventionTips":["Use a typed Cancelled error instead of string matching","Only cancel the token when the user explicitly aborts"],"tags":["cancellation","torrent","async"],"backgroundTag":"invalid-state-transition","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"}