spacedriveapp/spacedrive · error · anyhow::Error

Failed to send request: {}

Error message

Failed to send request: {}

What it means

Writing the serialized request body failed after the length prefix went out. Same failure class as the length-prefix write - connection lost or stream reset mid-write - with a larger window because the body is much bigger than 4 bytes.

Source

Thrown at core/src/service/network/protocol/sync/transport.rs:172

		})?;

		// Open bidirectional stream
		let (mut send, mut recv) = conn
			.open_bi()
			.await
			.map_err(|e| anyhow::anyhow!("Failed to open bidirectional stream: {}", e))?;

		// Serialize and send request
		let req_bytes = serde_json::to_vec(&request)
			.map_err(|e| anyhow::anyhow!("Failed to serialize sync request: {}", e))?;

		let len = req_bytes.len() as u32;
		send.write_all(&len.to_be_bytes())
			.await
			.map_err(|e| anyhow::anyhow!("Failed to send length: {}", e))?;
		send.write_all(&req_bytes)
			.await
			.map_err(|e| anyhow::anyhow!("Failed to send request: {}", e))?;

		// Properly close send stream
		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];

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Retry the request on a fresh connection
  2. Cap sync request payload size and paginate large operations
  3. Log bytes.len() with the error to spot oversized payloads
Defensive patterns

Strategy: retry

Try / catch

Err(e) if e.to_string().contains("Failed to send request") => {
    // body write failed: connection dropped mid-transfer, retry once
    retry_request_on_fresh_connection(device, request).await
}

Prevention

When it happens

Trigger: Connection drop during body transfer; peer resetting the stream after reading only the prefix; very large payloads failing as the link degrades.

Common situations: Large sync diffs over slow links; peer standby mid-transfer.

Related errors


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