{"record":{"id":"f80d95078198069e","repo":"tonhowtf/omniget","slug":"send-cancelled-during-transfer-mod","errorCode":null,"errorMessage":"Send cancelled during transfer","messagePattern":"Send cancelled during transfer","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"src-tauri/src/platforms/p2p/mod.rs","lineNumber":315,"sourceCode":"\n    if ok_response != \"OK\" {\n        anyhow::bail!(\"Receiver rejected transfer: {}\", ok_response);\n    }\n\n    *session.status.lock().await = \"transferring\".to_string();\n    tracing::info!(\n        \"[p2p] transferring: {} ({} bytes)\",\n        session.file_name,\n        session.file_size\n    );\n\n    let mut file = File::open(&session.file_path).await?;\n    let mut buf = vec![0u8; CHUNK_SIZE];\n    let mut sent: u64 = 0;\n\n    loop {\n        if cancel.is_cancelled() {\n            anyhow::bail!(\"Send cancelled during transfer\");\n        }\n\n        while session.paused.load(std::sync::atomic::Ordering::Relaxed) {\n            tokio::time::sleep(std::time::Duration::from_millis(100)).await;\n            if cancel.is_cancelled() {\n                anyhow::bail!(\"Send cancelled while paused\");\n            }\n        }\n\n        let n = file.read(&mut buf).await?;\n        if n == 0 {\n            break;\n        }\n\n        write_half.write_all(&buf[..n]).await?;\n        sent += n as u64;\n\n        *session.sent_bytes.lock().await = sent;","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/platforms/p2p/mod.rs#L297-L333","documentation":"At the top of each transfer loop iteration run_sender checks cancel.is_cancelled(); once the token fires mid-transfer it bails with \"Send cancelled during transfer\", stopping the file stream. Intentional cancellation, not a data or network failure.","triggerScenarios":"cancel_token.cancel() while the loop is actively reading the file and writing chunks (status == \"transferring\").","commonSituations":"User hits stop mid-transfer; UI cancels on window close; a new send session replaces a stale one and cancels the old token.","solutions":["Expected behavior — catch it, set session status to cancelled, and inform the receiver side so it can clean up.","If it fires unexpectedly, look for stray cancel_token.clone() holders or timeout wrappers around the transfer.","Remember there is no resume; restart the whole send if the transfer must complete."],"exampleFix":"// before\nrun_sender(session).await?; // cancelled error bubbles as failure\n// after\nif let Err(e) = run_sender(session).await {\n    if e.to_string().contains(\"Send cancelled\") { ui.mark_cancelled(&session.id); }\n    else { return Err(e); }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_sender(session.clone(), cancel.clone()).await {\n    Err(e) if e.to_string().contains(\"Send cancelled during transfer\") => {\n        session.status.lock().await = \"cancelled\".into();\n        ui.mark_transfer_stopped(&session.id);\n    }\n    other => other?,\n}","preventionTips":["Confirm before cancelling transfers that are nearly complete.","Never cancel tokens on transient UI events (e.g. navigation) without user intent.","Notify the receiver path so it can clean up its partial file too.","Remember transfers are non-resumable; warn users before mid-transfer cancellation."],"tags":["cancellation","p2p","transfer","control-flow"],"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"}