{"record":{"id":"23594c2efcab3e1a","repo":"spacedriveapp/spacedrive","slug":"failed-to-read-message-type","errorCode":null,"errorMessage":"Failed to read message type: {}","messagePattern":"Failed to read message type: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":632,"sourceCode":"\t\t));\n\n\t\t// Track whether we received a proper TransferComplete message\n\t\tlet mut transfer_completed = false;\n\n\t\t// Receive file chunks\n\t\tloop {\n\t\t\tlet mut msg_type = [0u8; 1];\n\t\t\tmatch recv_stream.read_exact(&mut msg_type).await {\n\t\t\t\tOk(_) => {}\n\t\t\t\tErr(e) => {\n\t\t\t\t\t// Check if this is an expected EOF (connection closed cleanly)\n\t\t\t\t\tlet err_str = e.to_string();\n\t\t\t\t\tif err_str.contains(\"finish\") || err_str.contains(\"closed\") {\n\t\t\t\t\t\t// Connection closed - will check transfer_completed below\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tlet _ = fs::remove_file(&final_dest_path).await;\n\t\t\t\t\treturn Err(anyhow::anyhow!(\"Failed to read message type: {}\", e));\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet mut len_buf = [0u8; 4];\n\t\t\trecv_stream.read_exact(&mut len_buf).await?;\n\t\t\tlet msg_len = u32::from_be_bytes(len_buf) as usize;\n\n\t\t\tlet mut msg_buf = vec![0u8; msg_len];\n\t\t\trecv_stream.read_exact(&mut msg_buf).await?;\n\n\t\t\tlet msg: crate::service::network::protocol::file_transfer::FileTransferMessage =\n\t\t\t\trmp_serde::from_slice(&msg_buf)?;\n\n\t\t\tmatch msg {\n\t\t\t\tcrate::service::network::protocol::file_transfer::FileTransferMessage::FileChunk {\n\t\t\t\t\tchunk_index,\n\t\t\t\t\tdata,\n\t\t\t\t\tchunk_checksum,","sourceCodeStart":614,"sourceCodeEnd":650,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L614-L650","documentation":"Inside the chunk-receive loop, recv_stream.read_exact failed with an error that is neither a clean EOF (the code treats error text containing 'finish' or 'closed' as expected end-of-stream, strategy.rs:624-630). The stream broke mid-transfer — reset, timeout, or peer crash. The partial destination file is deleted and all accumulated progress is lost; the pull restarts from byte zero.","triggerScenarios":"Peer daemon crashes or disconnects mid-send; network interruption resets the iroh stream; read timeout on a stalled link; either daemon restarting during the copy.","commonSituations":"Large files over unstable links; remote device sleeping mid-transfer; daemon upgrade/restart while jobs are in flight.","solutions":["Retry the pull job — the transfer is not resumable, so it restarts from the beginning","Keep both devices awake and daemons running for the duration of large transfers","Check the remote daemon's logs for crashes around the failure time","For repeatedly failing links, copy in smaller batches or stabilize connectivity first"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match remote_strategy.execute_pull(ctx, &src, &dst).await {\n    Ok(n) => Ok(n),\n    Err(e) if e.to_string().starts_with(\"Failed to read message type\") => {\n        // partial file already removed by the strategy; safe to restart from zero\n        schedule_retry_with_backoff(job_id, 3).await;\n        Err(e)\n    }\n    Err(e) => Err(e),\n}","preventionTips":["Treat mid-transfer stream breaks as retryable; the strategy cleans the partial file","Keep both daemons alive during large transfers (disable sleep on laptops)","Batch very large files on unstable links to reduce restart cost"],"tags":["rust","spacedrive","pull","network-interruption","stream","transfer-abort"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}