{"record":{"id":"b1ba9efb0b916c6d","repo":"spacedriveapp/spacedrive","slug":"network-endpoint-not-initialized","errorCode":null,"errorMessage":"Network endpoint not initialized","messagePattern":"Network endpoint not initialized","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"core/src/service/network/protocol/sync/transport.rs","lineNumber":143,"sourceCode":"\t\t\t\t\t\t\"Device {} not found in registry (not paired or offline)\",\n\t\t\t\t\t\ttarget_device\n\t\t\t\t\t)\n\t\t\t\t})?\n\t\t};\n\n\t\tdebug!(\n\t\t\tdevice_uuid = %target_device,\n\t\t\tnode_id = %node_id,\n\t\t\tmessage_type = ?std::mem::discriminant(&request),\n\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","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/protocol/sync/transport.rs#L125-L161","documentation":"Thrown by send_sync_request on the NetworkTransport impl for NetworkingService. The service stores its iroh Endpoint as an Option because the endpoint is created asynchronously during network service startup; this error means the request was issued while self.endpoint is still None. It is an initialization-ordering failure, not a network failure.","triggerScenarios":"Calling send_sync_request before the NetworkingService finished creating and assigning its iroh Endpoint; issuing sync requests while the daemon is restarting or shutting down; constructing the service in tests without starting networking.","commonSituations":"Startup race where a library sync job spawns before network init completes; daemon restart while sync jobs are queued; unit tests hitting the transport on a bare NetworkingService.","solutions":["Await the network service readiness signal before scheduling any sync jobs","Initialize or inject the endpoint before the sync layer becomes callable","At call sites, treat this error as 'not ready': skip the sync cycle instead of failing the job","Expose an endpoint()/is_ready() check and assert on it in debug builds"],"exampleFix":"// before\nlet response = net.send_sync_request(device, request).await?;\n\n// after\nif net.endpoint().is_none() {\n    tracing::warn!(device = %device, \"sync skipped: network endpoint not ready\");\n    return Ok(());\n}\nlet response = net.send_sync_request(device, request).await?;","handlingStrategy":"validation","validationCode":"// Run before any sync request\ndebug_assert!(net.endpoint().is_some(), \"network endpoint missing\");\nif net.endpoint().is_none() {\n    // defer this sync cycle until the network service is ready\n    return;\n}\nnet.send_sync_request(device, request).await?;","typeGuard":"fn is_endpoint_uninitialized(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"Network endpoint not initialized\")\n}","tryCatchPattern":"match net.send_sync_request(device, request).await {\n    Ok(resp) => { /* ... */ }\n    Err(e) if is_endpoint_uninitialized(&e) => {\n        // setup bug: do not retry; surface to operator or defer the sync cycle\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Start the network service and await its ready event before enabling sync jobs","Model a missing endpoint as a deferred state, not an error, at the call site","Cover the startup ordering in tests so sync cannot run before the endpoint exists"],"tags":["network","iroh","initialization","sync","rust"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}