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

  1. Retry the pull job — the transfer is not resumable, so it restarts from the beginning
  2. Keep both devices awake and daemons running for the duration of large transfers
  3. Check the remote daemon's logs for crashes around the failure time
  4. 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

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


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/23594c2efcab3e1a. Report an issue: GitHub.