{"record":{"id":"a685bf362693b1bd","repo":"spacedriveapp/spacedrive","slug":"failed-to-write-message","errorCode":null,"errorMessage":"Failed to write message: {}","messagePattern":"Failed to write message: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/transports/sync.rs","lineNumber":142,"sourceCode":"\t\tlet mut send = conn\n\t\t\t.open_uni()\n\t\t\t.await\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to open stream: {}\", e))?;\n\n\t\t// Write length prefix (required by multiplexer)\n\t\tlet len = 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 write length prefix: {}\", e))?;\n\n\t\t// Write message bytes\n\t\tsend.write_all(&bytes).await.map_err(|e| {\n\t\t\twarn!(\n\t\t\t\tdevice_uuid = %target_device,\n\t\t\t\terror = %e,\n\t\t\t\t\"Failed to write sync message to stream\"\n\t\t\t);\n\t\t\tanyhow::anyhow!(\"Failed to write message: {}\", e)\n\t\t})?;\n\n\t\tsend.finish()\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to finish stream: {}\", e))?;\n\n\t\ttracing::info!(\n\t\t\t\"Sync message sent successfully to device {} ({} bytes via uni stream)\",\n\t\t\ttarget_device,\n\t\t\tbytes.len()\n\t\t);\n\n\t\tOk(())\n\t}\n\n\t/// Send a sync request and wait for response\n\t///\n\t/// Uses bidirectional streams for proper request/response pattern (Iroh best practice)\n\tasync fn send_sync_request(","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/transports/sync.rs#L124-L160","documentation":"Writing the serialized SyncMessage body to the unidirectional stream failed after the length prefix was accepted. Same class as the prefix write - connection lost or stream reset mid-write - with a longer exposure window for larger payloads.","triggerScenarios":"Connection drop during body transfer; peer resetting the stream after reading only the prefix; oversized messages failing on degraded links.","commonSituations":"Large messages (big diffs, many records) over slow links; peer standby mid-transfer.","solutions":["Retry the send on a fresh connection","Cap message size and chunk large payloads at the protocol level","Log bytes.len() with the error to identify oversized messages"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Err(e) if e.to_string().contains(\"Failed to write message\") => {\n    // body write failed mid-transfer: reconnect and resend once\n    active_connections.write().await.remove(&cache_key);\n    retry_send_on_fresh_connection(device, node_id, bytes).await\n}","preventionTips":["Cap and chunk large sync messages","Log message size with write errors","Retry once on a fresh connection before marking the peer offline"],"tags":["network","iroh","quic","streams","sync","rust"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}