{"record":{"id":"e0f7b29807002bab","repo":"spacedriveapp/spacedrive","slug":"failed-to-send-length-e0f7b2","errorCode":null,"errorMessage":"Failed to send length: {}","messagePattern":"Failed to send length: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/transports/sync.rs","lineNumber":266,"sourceCode":"\t\t\t}\n\n\t\t\tnew_conn\n\t\t};\n\n\t\t// Open bidirectional stream\n\t\tlet (mut send, mut recv) = conn\n\t\t\t.open_bi()\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to open bidirectional stream: {}\", e))?;\n\n\t\t// Serialize and send request\n\t\tlet req_bytes = serde_json::to_vec(&request)\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to serialize sync request: {}\", e))?;\n\n\t\tlet len = req_bytes.len() as u32;\n\t\tsend.write_all(&len.to_be_bytes())\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to send length: {}\", e))?;\n\t\tsend.write_all(&req_bytes)\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to send request: {}\", e))?;\n\n\t\t// Properly close send stream\n\t\tsend.finish()\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to finish stream: {}\", e))?;\n\n\t\tdebug!(\"Sync request sent, waiting for response...\");\n\n\t\t// Read response with timeout\n\t\tlet result = timeout(Duration::from_secs(60), async {\n\t\t\tlet mut len_buf = [0u8; 4];\n\t\t\trecv.read_exact(&mut len_buf)\n\t\t\t\t.await\n\t\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to read response length: {}\", e))?;\n\t\t\tlet resp_len = u32::from_be_bytes(len_buf) as usize;\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/transports/sync.rs#L248-L284","documentation":"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.","triggerScenarios":"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.","commonSituations":"Flaky links, peers under memory pressure closing streams, shutdown races in tests.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = send.write_all(&len.to_be_bytes()).await {\n    active_connections.write().await.remove(&cache_key);\n    // retry the whole send once on a fresh connection, only if the request is idempotent\n}","preventionTips":["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"],"tags":["network","sync","quic","write"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}