{"record":{"id":"003b7248c23c8fa1","repo":"spacedriveapp/spacedrive","slug":"failed-to-write-message-length","errorCode":null,"errorMessage":"Failed to write message length: {}","messagePattern":"Failed to write message length: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":1217,"sourceCode":"\t\tlet encrypted_data = chunk_data.to_vec();\n\t\tlet nonce = [0u8; 12]; // Dummy nonce since we're not encrypting\n\n\t\tlet chunk_message =\n\t\t\tcrate::service::network::protocol::file_transfer::FileTransferMessage::FileChunk {\n\t\t\t\ttransfer_id,\n\t\t\t\tchunk_index,\n\t\t\t\tdata: encrypted_data,\n\t\t\t\tnonce,\n\t\t\t\tchunk_checksum: *chunk_checksum.as_bytes(),\n\t\t\t};\n\n\t\tlet message_data = rmp_serde::to_vec(&chunk_message)?;\n\n\t\tsend_stream.write_u8(0).await?;\n\t\tsend_stream\n\t\t\t.write_all(&(message_data.len() as u32).to_be_bytes())\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to write message length: {}\", e))?;\n\t\tsend_stream\n\t\t\t.write_all(&message_data)\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to write chunk data: {}\", e))?;\n\t\tsend_stream\n\t\t\t.flush()\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to flush stream: {}\", e))?;\n\n\t\tfile_transfer_protocol.record_chunk_received(\n\t\t\t&transfer_id,\n\t\t\tchunk_index,\n\t\t\tbytes_read as u64,\n\t\t)?;\n\n\t\tbytes_transferred += bytes_read as u64;\n\t\tif let Some(callback) = progress_callback {\n\t\t\tcallback(bytes_transferred, total_size);","sourceCodeStart":1199,"sourceCodeEnd":1235,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L1199-L1235","documentation":"While streaming 64 KiB encrypted chunks, write_all of the 4-byte length prefix failed on the send stream. This is a connection-level failure surfaced at the next write: the peer disconnected, the connection was reset, or a connection error occurred after the previous chunk. Failing at the length prefix rather than mid-payload means the stream broke between chunks.","triggerScenarios":"Peer drops the connection between chunk writes; peer daemon crashes while processing a previous chunk; network path change (IP rotation) kills the QUIC connection before the next frame is queued.","commonSituations":"Peer OOM or crash mid-transfer, mobile or VPN networks forcing reconnection, peer disk-full causing its receive side to abort the session.","solutions":["Retry the copy job - chunk state is recorded per session and the transfer restarts cleanly","Check the peer daemon for crashes or OOM kills at the failure timestamp","Stabilize the network path (avoid network switching during transfers)","Verify the peer has free disk space for the incoming file"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Stream writes fail with the connection; retry the whole transfer, not the single write.\nlet mut attempt = 0;\nloop {\n    attempt += 1;\n    match stream_file_data(/* ... */).await {\n        Ok(()) => break,\n        Err(ref e) if e.to_string().contains(\"write\") && attempt < 3 => {\n            tokio::time::sleep(std::time::Duration::from_secs(attempt as u64)).await;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["Free disk space on receivers before large transfers","Keep devices on stable power and network during transfers","Let the resumable job system handle restarts"],"tags":["network","file-transfer","quic","streaming"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}