{"record":{"id":"8ffdbe83a933e715","repo":"spacedriveapp/spacedrive","slug":"failed-to-finish-stream-8ffdbe","errorCode":null,"errorMessage":"Failed to finish stream: {}","messagePattern":"Failed to finish stream: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/transports/sync.rs","lineNumber":146,"sourceCode":"\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(\n\t\t&self,\n\t\ttarget_device: Uuid,\n\t\trequest: SyncMessage,\n\t) -> Result<SyncMessage> {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/transports/sync.rs#L128-L164","documentation":"send.finish() on the unidirectional stream failed because the stream was already closed or reset - typically the peer reset the stream before consuming the message. For fire-and-forget sends this mostly means the peer rejected or dropped the stream early.","triggerScenarios":"Peer reset the uni stream on receipt (shutdown, unknown message, handler gone); connection lost between the body write and finish; finishing an already-finished stream.","commonSituations":"Peer app closing during sync; peer version that resets streams for unknown message types.","solutions":["Inspect peer logs for the reset reason","Reconnect and resend once","Verify protocol version compatibility for the message type being sent"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"fn is_finish_failure(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"Failed to finish stream\")\n}","tryCatchPattern":"if let Err(e) = net.send_sync_message(device, msg).await {\n    if is_finish_failure(&e) {\n        // peer reset the stream early; check peer logs before resending,\n        // since the message may already have been consumed\n    }\n}","preventionTips":["Inspect peer reset reasons when finish fails repeatedly","Resend only after confirming the peer did not process the message","Keep peers version-aligned to avoid unsupported-message resets"],"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"}