spacedriveapp/spacedrive · error · anyhow::Error

Failed to read response: {}

Error message

Failed to read response: {}

What it means

The response length header arrived but recv.read_exact for the body failed before resp_len bytes were read: the response was truncated by a dropped connection, or the peer's header claimed more bytes than it sent. The length is untrusted input taken from the wire.

Source

Thrown at core/src/service/network/transports/sync.rs:290

		send.finish()
			.map_err(|e| anyhow::anyhow!("Failed to finish stream: {}", e))?;

		debug!("Sync request sent, waiting for response...");

		// Read response with timeout
		let result = timeout(Duration::from_secs(60), async {
			let mut len_buf = [0u8; 4];
			recv.read_exact(&mut len_buf)
				.await
				.map_err(|e| anyhow::anyhow!("Failed to read response length: {}", e))?;
			let resp_len = u32::from_be_bytes(len_buf) as usize;

			debug!("Receiving sync response of {} bytes", resp_len);

			let mut resp_buf = vec![0u8; resp_len];
			recv.read_exact(&mut resp_buf)
				.await
				.map_err(|e| anyhow::anyhow!("Failed to read response: {}", e))?;
			Ok::<_, anyhow::Error>(resp_buf)
		})
		.await;

		let resp_buf = match result {
			Ok(Ok(buf)) => buf,
			Ok(Err(e)) => return Err(e),
			Err(_) => {
				return Err(anyhow::anyhow!(
					"Sync request timed out after 60s - peer {} not responding",
					target_device
				))
			}
		};

		// Deserialize response
		let response: SyncMessage = serde_json::from_slice(&resp_buf)
			.map_err(|e| anyhow::anyhow!("Failed to deserialize sync response: {}", e))?;

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Retry the request; truncation is transient when the link is the cause
  2. If reproducible with one peer, capture that peer's outbound serialization for the message and check the length prefix it writes
  3. For large payloads, prefer chunked or paginated sync responses instead of one big frame
Defensive patterns

Strategy: retry

Try / catch

if recv.read_exact(&mut resp_buf).await.is_err() {
    // truncated response: retry the request; if it repeats with one peer, inspect its serialization
}

Prevention

When it happens

Trigger: Connection lost while a large response was in flight; a peer bug writing a wrong length prefix; peer aborted mid-serialization of a big sync response.

Common situations: Large sync responses (big diffs, many records) over unstable links.

Related errors


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