{"record":{"id":"49a802029a67d0f4","repo":"spacedriveapp/spacedrive","slug":"failed-to-flush-stream","errorCode":null,"errorMessage":"Failed to flush stream: {}","messagePattern":"Failed to flush stream: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/ops/files/copy/strategy.rs","lineNumber":1225,"sourceCode":"\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);\n\t\t}\n\n\t\tchunk_index += 1;\n\n\t\tif chunk_index == 1 || chunk_index % 100 == 0 || chunk_index == total_chunks as u32 {\n\t\t\tctx.log(format!(\n\t\t\t\t\"Sent chunk {}/{} ({} bytes total)\",\n\t\t\t\tchunk_index, total_chunks, bytes_transferred","sourceCodeStart":1207,"sourceCodeEnd":1243,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/ops/files/copy/strategy.rs#L1207-L1243","documentation":"flush() on the send stream failed after a chunk was written. Everything written so far was buffered and could not be pushed to the transport, which means the connection is broken. Functionally identical to the write failures: the transport under the stream died and the transfer aborts at the current chunk.","triggerScenarios":"Connection closed by peer or network while buffered chunk data was still pending; QUIC connection error surfacing at flush time; send-side buffer invalidation after a reset.","commonSituations":"Same environmental causes as mid-stream write failures: peer disconnects, network drops, device sleep events during large transfers.","solutions":["Retry the copy job","Check peer connectivity and daemon health at the failure time","Reduce concurrent transfers if the peer is saturated","If reproducible on one link only, capture QUIC logs to identify which side closed"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Flush failure equals a dead connection: retry the transfer, never the flush alone.\nmatch run_push_transfer().await {\n    Ok(()) => Ok(()),\n    Err(ref e) if e.to_string().contains(\"flush\") => {\n        tokio::time::sleep(std::time::Duration::from_secs(2)).await;\n        run_push_transfer().await\n    }\n    Err(e) => Err(e.clone()),\n}","preventionTips":["Keep peer connectivity stable through the whole job","Reduce concurrent transfers when peers are saturated"],"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"}