spacedriveapp/spacedrive · error · anyhow::Error

Failed to send request: {}

Error message

Failed to send request: {}

What it means

send.write_all of the serialized request body failed after the length prefix was written. The connection degraded mid-write: the peer closed the stream or connection, or the local endpoint stopped. Partial delivery is possible, so the peer may have received a truncated frame.

Source

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

		};

		// 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; sync requests must be idempotent on the peer side for this to be safe
  2. If the payload is large, split it into smaller messages so a single write failure costs less
  3. Check peer reachability if the same device fails repeatedly
Defensive patterns

Strategy: retry

Try / catch

if send.write_all(&req_bytes).await.is_err() {
    active_connections.write().await.remove(&cache_key);
    // full-send retry on a new connection; peer must tolerate duplicates
}

Prevention

When it happens

Trigger: Peer drops the connection while the request body is in flight; large sync requests exceeding a peer-side timeout; local endpoint shutdown mid-write.

Common situations: Unstable wireless links between devices; initial sync carrying a large request payload.

Related errors


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