spacedriveapp/spacedrive · error · anyhow::Error
Failed to flush stream: {}
Error message
Failed to flush stream: {} What it means
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.
Source
Thrown at core/src/ops/files/copy/strategy.rs:1225
nonce,
chunk_checksum: *chunk_checksum.as_bytes(),
};
let message_data = rmp_serde::to_vec(&chunk_message)?;
send_stream.write_u8(0).await?;
send_stream
.write_all(&(message_data.len() as u32).to_be_bytes())
.await
.map_err(|e| anyhow::anyhow!("Failed to write message length: {}", e))?;
send_stream
.write_all(&message_data)
.await
.map_err(|e| anyhow::anyhow!("Failed to write chunk data: {}", e))?;
send_stream
.flush()
.await
.map_err(|e| anyhow::anyhow!("Failed to flush stream: {}", e))?;
file_transfer_protocol.record_chunk_received(
&transfer_id,
chunk_index,
bytes_read as u64,
)?;
bytes_transferred += bytes_read as u64;
if let Some(callback) = progress_callback {
callback(bytes_transferred, total_size);
}
chunk_index += 1;
if chunk_index == 1 || chunk_index % 100 == 0 || chunk_index == total_chunks as u32 {
ctx.log(format!(
"Sent chunk {}/{} ({} bytes total)",
chunk_index, total_chunks, bytes_transferredView on GitHub (pinned to 6dfeccf211)
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
Defensive patterns
Strategy: retry
Try / catch
// Flush failure equals a dead connection: retry the transfer, never the flush alone.
match run_push_transfer().await {
Ok(()) => Ok(()),
Err(ref e) if e.to_string().contains("flush") => {
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
run_push_transfer().await
}
Err(e) => Err(e.clone()),
} Prevention
- Keep peer connectivity stable through the whole job
- Reduce concurrent transfers when peers are saturated
When it happens
Trigger: 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.
Common situations: Same environmental causes as mid-stream write failures: peer disconnects, network drops, device sleep events during large transfers.
Related errors
- Failed to write message length: {}
- Failed to write chunk data: {}
- Failed to open stream: {}
- Failed to finish stream: {}
- Transfer error: {}
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/49a802029a67d0f4.
Report an issue: GitHub.