spacedriveapp/spacedrive · error · anyhow::Error
Failed to read message type: {}
Error message
Failed to read message type: {} What it means
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.
Source
Thrown at core/src/ops/files/copy/strategy.rs:632
));
// Track whether we received a proper TransferComplete message
let mut transfer_completed = false;
// Receive file chunks
loop {
let mut msg_type = [0u8; 1];
match recv_stream.read_exact(&mut msg_type).await {
Ok(_) => {}
Err(e) => {
// Check if this is an expected EOF (connection closed cleanly)
let err_str = e.to_string();
if err_str.contains("finish") || err_str.contains("closed") {
// Connection closed - will check transfer_completed below
break;
}
let _ = fs::remove_file(&final_dest_path).await;
return Err(anyhow::anyhow!("Failed to read message type: {}", e));
}
}
let mut len_buf = [0u8; 4];
recv_stream.read_exact(&mut len_buf).await?;
let msg_len = u32::from_be_bytes(len_buf) as usize;
let mut msg_buf = vec![0u8; msg_len];
recv_stream.read_exact(&mut msg_buf).await?;
let msg: crate::service::network::protocol::file_transfer::FileTransferMessage =
rmp_serde::from_slice(&msg_buf)?;
match msg {
crate::service::network::protocol::file_transfer::FileTransferMessage::FileChunk {
chunk_index,
data,
chunk_checksum,View on GitHub (pinned to 6dfeccf211)
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
Defensive patterns
Strategy: retry
Try / catch
match remote_strategy.execute_pull(ctx, &src, &dst).await {
Ok(n) => Ok(n),
Err(e) if e.to_string().starts_with("Failed to read message type") => {
// partial file already removed by the strategy; safe to restart from zero
schedule_retry_with_backoff(job_id, 3).await;
Err(e)
}
Err(e) => Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Large files over unstable links; remote device sleeping mid-transfer; daemon upgrade/restart while jobs are in flight.
Related errors
- Failed to open bidirectional stream: {}
- Source must be a physical path for PULL operation
- Destination must be local path for PULL operation
- Could not resolve source device slug '{}' to UUID in library
- Could not find node_id for device {} (slug: {}). Device may
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/23594c2efcab3e1a.
Report an issue: GitHub.