spacedriveapp/spacedrive · error · anyhow::Error

Network endpoint not initialized

Error message

Network endpoint not initialized

What it means

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.

Source

Thrown at core/src/service/network/transports/sync.rs:62

				})?
		};

		tracing::info!(
			"Sending sync message to device {} (node {}), type: {:?}, library: {}",
			target_device,
			node_id,
			std::mem::discriminant(&message),
			message.library_id()
		);

		// 2. Serialize message to bytes
		let bytes = serde_json::to_vec(&message)
			.map_err(|e| anyhow::anyhow!("Failed to serialize sync message: {}", e))?;

		// 3. Get or create connection (with caching for massive performance improvement)
		let endpoint = self
			.endpoint()
			.ok_or_else(|| anyhow::anyhow!("Network endpoint not initialized"))?;

		let active_connections = self.active_connections();
		let cache_key = (node_id, SYNC_ALPN.to_vec());

		// Check cache first - reuse existing connection if alive
		let conn = {
			let connections = active_connections.read().await;
			if let Some(cached_conn) = connections.get(&cache_key) {
				if cached_conn.close_reason().is_none() {
					tracing::debug!(
						device_uuid = %target_device,
						"Reusing cached connection (avoids TLS handshake)"
					);
					Some(cached_conn.clone())
				} else {
					None // Connection closed, need new one
				}
			} else {

View on GitHub (pinned to 6dfeccf211)

Solutions

  1. Await network readiness before starting the sync engine that calls send_sync_message
  2. Treat this error as 'not ready' and drop or defer the message rather than failing the caller
  3. Ensure shutdown drains sync sends before the endpoint is dropped

Example fix

// before
net.send_sync_message(device, msg).await?;

// after
if net.endpoint().is_none() {
    tracing::warn!(device = %device, "dropping sync message: network not started");
    return Ok(());
}
net.send_sync_message(device, msg).await?;
Defensive patterns

Strategy: validation

Validate before calling

// Run before any fire-and-forget send
if net.endpoint().is_none() {
    // network not started: defer or drop the message by your durability policy
    return;
}
net.send_sync_message(device, message).await?;

Type guard

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

Try / catch

if let Err(e) = net.send_sync_message(device, msg).await {
    if is_endpoint_uninitialized(&e) {
        // ordering bug: defer the message; do not retry immediately
        queue_for_retry_after_network_ready(msg);
        return Ok(());
    }
    return Err(e);
}

Prevention

When it happens

Trigger: PeerSync emitting a message before the NetworkingService finished starting its endpoint; sending during daemon shutdown or restart; tests calling the transport without network init.

Common situations: Sync job racing network startup; queued outgoing messages flushed after shutdown began.

Related errors


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