spacedriveapp/spacedrive · error · anyhow::Error
Failed to write chunk data: {}
Error message
Failed to write chunk data: {} What it means
The serialized chunk payload (rmp-encoded chunk message) could not be written to the send stream. Same failure class as the length-prefix write, but failing mid-payload indicates an abrupt reset (stream or connection error) rather than a between-chunks disconnect. The transfer aborts at the current chunk.
Source
Thrown at core/src/ops/files/copy/strategy.rs:1221
crate::service::network::protocol::file_transfer::FileTransferMessage::FileChunk {
transfer_id,
chunk_index,
data: encrypted_data,
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;
View on GitHub (pinned to 6dfeccf211)
Solutions
- Retry the copy job from its recorded chunk state
- Inspect peer logs for why the receive side stopped (disk full, panic, restart)
- On slow links, verify keep-alive and idle settings suffice for the transfer duration
- Rule out middleboxes interfering with long-lived UDP flows
Defensive patterns
Strategy: retry
Try / catch
// A mid-payload reset kills the whole stream; rerun the transfer from its chunk state.
if let Err(ref e) = stream_file_data(/* ... */).await {
if e.to_string().contains("chunk data") {
tracing::warn!(error = %e, "stream reset mid-chunk, retrying transfer");
tokio::time::sleep(std::time::Duration::from_secs(2)).await;
return stream_file_data(/* ... */).await;
}
return Err(e.clone());
} Prevention
- Stabilize the network path for the transfer duration
- Watch peer receive-side logs for the originating reset
- Avoid mobile or switching networks for large pushes
When it happens
Trigger: Peer resets the stream while the payload write is in flight; connection-level error (timeout, path change) surfacing during a large write; send buffer invalidated by connection close.
Common situations: Peer application closed the stream abruptly, QUIC idle timeout exceeded on slow links, abrupt network transitions such as Wi-Fi to cellular.
Related errors
- Failed to write message length: {}
- Failed to flush stream: {}
- 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/b2c40c64bf686b67.
Report an issue: GitHub.