spacedriveapp/spacedrive · error · anyhow::Error
Failed to send length: {}
Error message
Failed to send length: {} What it means
send.write_all on the 4-byte big-endian length prefix failed at the very start of the request write. At that moment the QUIC connection or stream died: the peer reset the stream immediately, the connection was lost right after connect, or the local endpoint was stopped mid-send.
Source
Thrown at core/src/service/network/transports/sync.rs:266
}
new_conn
};
// 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;
View on GitHub (pinned to 6dfeccf211)
Solutions
- Evict the cached connection for this cache_key and retry the request once over a new connection
- If it repeats for one specific peer, check that peer's logs for stream resets or panics in the sync handler
- Make shutdown cancel in-flight sync sends so they fail with a cancellation instead of a write error
Defensive patterns
Strategy: retry
Try / catch
if let Err(e) = send.write_all(&len.to_be_bytes()).await {
active_connections.write().await.remove(&cache_key);
// retry the whole send once on a fresh connection, only if the request is idempotent
} Prevention
- Make sync requests idempotent so a retry after a failed prefix write is safe
- Evict the connection on any write error so later sends reconnect
- Cancel in-flight sends during shutdown
When it happens
Trigger: Peer accepts the connection then resets the sync stream (handler panic or protocol mismatch); connection lost in the window between connect() and the first write; daemon shutdown dropping the endpoint during the send.
Common situations: Flaky links, peers under memory pressure closing streams, shutdown races in tests.
Related errors
- Failed to send request: {}
- Failed to open bidirectional stream: {}
- Failed to send length: {}
- Failed to send request: {}
- Failed to read response length: {}
AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16).
Data as JSON: /api/errors/e0f7b29807002bab.
Report an issue: GitHub.