{"record":{"id":"fb53950bf35829fc","repo":"spacedriveapp/spacedrive","slug":"network-endpoint-not-initialized-fb5395","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/transports/sync.rs","lineNumber":62,"sourceCode":"\t\t\t\t})?\n\t\t};\n\n\t\ttracing::info!(\n\t\t\t\"Sending sync message to device {} (node {}), type: {:?}, library: {}\",\n\t\t\ttarget_device,\n\t\t\tnode_id,\n\t\t\tstd::mem::discriminant(&message),\n\t\t\tmessage.library_id()\n\t\t);\n\n\t\t// 2. Serialize message to bytes\n\t\tlet bytes = serde_json::to_vec(&message)\n\t\t\t.map_err(|e| anyhow::anyhow!(\"Failed to serialize sync message: {}\", e))?;\n\n\t\t// 3. Get or create connection (with caching for massive performance improvement)\n\t\tlet endpoint = self\n\t\t\t.endpoint()\n\t\t\t.ok_or_else(|| anyhow::anyhow!(\"Network endpoint not initialized\"))?;\n\n\t\tlet active_connections = self.active_connections();\n\t\tlet cache_key = (node_id, SYNC_ALPN.to_vec());\n\n\t\t// Check cache first - reuse existing connection if alive\n\t\tlet conn = {\n\t\t\tlet connections = active_connections.read().await;\n\t\t\tif let Some(cached_conn) = connections.get(&cache_key) {\n\t\t\t\tif cached_conn.close_reason().is_none() {\n\t\t\t\t\ttracing::debug!(\n\t\t\t\t\t\tdevice_uuid = %target_device,\n\t\t\t\t\t\t\"Reusing cached connection (avoids TLS handshake)\"\n\t\t\t\t\t);\n\t\t\t\t\tSome(cached_conn.clone())\n\t\t\t\t} else {\n\t\t\t\t\tNone // Connection closed, need new one\n\t\t\t\t}\n\t\t\t} else {","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/core/src/service/network/transports/sync.rs#L44-L80","documentation":"The endpoint() accessor returned None in send_sync_message (transports/sync.rs). As with the request path, the iroh Endpoint is optional because it is created during network service startup; the error means a fire-and-forget sync send was attempted before the endpoint existed or after it was dropped.","triggerScenarios":"PeerSync emitting a message before the NetworkingService finished starting its endpoint; sending during daemon shutdown or restart; tests calling the transport without network init.","commonSituations":"Sync job racing network startup; queued outgoing messages flushed after shutdown began.","solutions":["Await network readiness before starting the sync engine that calls send_sync_message","Treat this error as 'not ready' and drop or defer the message rather than failing the caller","Ensure shutdown drains sync sends before the endpoint is dropped"],"exampleFix":"// before\nnet.send_sync_message(device, msg).await?;\n\n// after\nif net.endpoint().is_none() {\n    tracing::warn!(device = %device, \"dropping sync message: network not started\");\n    return Ok(());\n}\nnet.send_sync_message(device, msg).await?;","handlingStrategy":"validation","validationCode":"// Run before any fire-and-forget send\nif net.endpoint().is_none() {\n    // network not started: defer or drop the message by your durability policy\n    return;\n}\nnet.send_sync_message(device, message).await?;","typeGuard":"fn is_endpoint_uninitialized(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"Network endpoint not initialized\")\n}","tryCatchPattern":"if let Err(e) = net.send_sync_message(device, msg).await {\n    if is_endpoint_uninitialized(&e) {\n        // ordering bug: defer the message; do not retry immediately\n        queue_for_retry_after_network_ready(msg);\n        return Ok(());\n    }\n    return Err(e);\n}","preventionTips":["Start networking before starting the sync engine that emits messages","Drain outgoing sync messages during shutdown before the endpoint drops","Expose and check endpoint presence in test fixtures"],"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"}