spacedriveapp/spacedrive · error · anyhow::Error

Network endpoint not initialized

Error message

Network endpoint not initialized

What it means

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.

Source

Thrown at core/src/service/network/protocol/sync/transport.rs:143

						"Device {} not found in registry (not paired or offline)",
						target_device
					)
				})?
		};

		debug!(
			device_uuid = %target_device,
			node_id = %node_id,
			message_type = ?std::mem::discriminant(&request),
			library_id = %request.library_id(),
			"Sending sync request"
		);

		// Get endpoint
		let endpoint = self
			.endpoint
			.as_ref()
			.ok_or_else(|| anyhow::anyhow!("Network endpoint not initialized"))?;

		// Connect with SYNC_ALPN
		let conn = endpoint.connect(node_id.into(), SYNC_ALPN).await.map_err(|e| {
			warn!(
				device_uuid = %target_device,
				node_id = %node_id,
				error = %e,
				"Failed to connect to device for sync request"
			);
			anyhow::anyhow!("Failed to connect to {}: {}", target_device, e)
		})?;

		// Open bidirectional stream
		let (mut send, mut recv) = conn
			.open_bi()
			.await
			.map_err(|e| anyhow::anyhow!("Failed to open bidirectional stream: {}", e))?;

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Await the network service readiness signal before scheduling any sync jobs
  2. Initialize or inject the endpoint before the sync layer becomes callable
  3. At call sites, treat this error as 'not ready': skip the sync cycle instead of failing the job
  4. Expose an endpoint()/is_ready() check and assert on it in debug builds

Example fix

// before
let response = net.send_sync_request(device, request).await?;

// after
if net.endpoint().is_none() {
    tracing::warn!(device = %device, "sync skipped: network endpoint not ready");
    return Ok(());
}
let response = net.send_sync_request(device, request).await?;
Defensive patterns

Strategy: validation

Validate before calling

// Run before any sync request
debug_assert!(net.endpoint().is_some(), "network endpoint missing");
if net.endpoint().is_none() {
    // defer this sync cycle until the network service is ready
    return;
}
net.send_sync_request(device, request).await?;

Type guard

fn is_endpoint_uninitialized(err: &anyhow::Error) -> bool {
    err.to_string().contains("Network endpoint not initialized")
}

Try / catch

match net.send_sync_request(device, request).await {
    Ok(resp) => { /* ... */ }
    Err(e) if is_endpoint_uninitialized(&e) => {
        // setup bug: do not retry; surface to operator or defer the sync cycle
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spacedriveapp/spacedrive@6dfeccf211 (2026-08-16). Data as JSON: /api/errors/b1ba9efb0b916c6d. Report an issue: GitHub.