{"record":{"id":"7dd7261e861cc4b8","repo":"spacedriveapp/spacedrive","slug":"failed-to-connect-to","errorCode":null,"errorMessage":"Failed to connect to {}: {}","messagePattern":"Failed to connect to (.+?): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/protocol/sync/transport.rs","lineNumber":153,"sourceCode":"\t\t\tlibrary_id = %request.library_id(),\n\t\t\t\"Sending sync request\"\n\t\t);\n\n\t\t// Get endpoint\n\t\tlet endpoint = self\n\t\t\t.endpoint\n\t\t\t.as_ref()\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Network endpoint not initialized\"))?;\n\n\t\t// Connect with SYNC_ALPN\n\t\tlet conn = endpoint.connect(node_id.into(), SYNC_ALPN).await.map_err(|e| {\n\t\t\twarn!(\n\t\t\t\tdevice_uuid = %target_device,\n\t\t\t\tnode_id = %node_id,\n\t\t\t\terror = %e,\n\t\t\t\t\"Failed to connect to device for sync request\"\n\t\t\t);\n\t\t\tanyhow::anyhow!(\"Failed to connect to {}: {}\", target_device, e)\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","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/protocol/sync/transport.rs#L135-L171","documentation":"endpoint.connect(node_id.into(), SYNC_ALPN) failed inside send_sync_request. Iroh must resolve the peer NodeId to reachable addresses (discovery, relays, cached direct addresses) and complete a QUIC/TLS handshake for the sync ALPN; the appended text is the underlying iroh error. It means the peer was unreachable at the transport level, not that sync logic failed.","triggerScenarios":"Target device powered off or asleep; peer NodeId stale after an identity reset; no relay/discovery configured so the NodeId cannot be resolved to addresses; both peers behind restrictive NATs; ALPN mismatch because the peer runs a different spacedrive version.","commonSituations":"Syncing to a laptop that went to sleep; peer changed network leaving only stale address records; one device upgraded so SYNC_ALPN changed; air-gapped or relay-blocked networks.","solutions":["Confirm the peer is online and paired (presence/heartbeat) before initiating sync","Verify iroh relay and discovery configuration on both peers","Retry with backoff - relay path establishment is often transient","Re-pair the devices if the peer reset its identity (new NodeId)","Ensure both devices run versions that agree on SYNC_ALPN"],"exampleFix":"// before\nlet resp = net.send_sync_request(device, req).await?;\n\n// after\nlet resp = match net.send_sync_request(device, req.clone()).await {\n    Ok(resp) => resp,\n    Err(e) if is_connect_failure(&e) => {\n        tokio::time::sleep(std::time::Duration::from_secs(2)).await;\n        net.send_sync_request(device, req).await? // single retry\n    }\n    Err(e) => return Err(e),\n};","handlingStrategy":"retry","validationCode":"// Best-effort pre-check: skip peers not marked online\nif !device_presence.is_online(device) {\n    return Ok(None);\n}\nnet.send_sync_request(device, request).await?;","typeGuard":"fn is_connect_failure(err: &anyhow::Error) -> bool {\n    err.to_string().starts_with(\"Failed to connect to\")\n}","tryCatchPattern":"let mut attempt = 0;\nloop {\n    match net.send_sync_request(device, request.clone()).await {\n        Ok(resp) => break Ok(resp),\n        Err(e) if is_connect_failure(&e) && attempt < 2 => {\n            attempt += 1;\n            tokio::time::sleep(std::time::Duration::from_secs(2u64 * attempt)).await;\n        }\n        Err(e) if is_connect_failure(&e) => {\n            mark_device_offline(device);\n            break Err(e);\n        }\n        Err(e) => break Err(e),\n    }\n}","preventionTips":["Keep relay and discovery endpoints configured and reachable on all devices","Check peer presence before initiating sync and skip offline peers","Upgrade devices together so SYNC_ALPN stays identical","Re-pair devices after any identity reset so NodeIds are current"],"tags":["network","iroh","connectivity","sync","rust"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}