nautechsystems/nautilus_trader · error · anyhow::Error

Component '{id}' not found in global registry

Error message

Component '{id}' not found in global registry

What it means

During teardown, `release_component_subscriptions` looks up a component by ID in the process-global component registry before releasing its subscriptions. The registry has no component registered under that UUID4, so the lookup fails and an anyhow error is returned. This indicates a component was disposed (or its ID fabricated) without ever being registered, or it was already removed by an earlier release/dispose pass.

Source

Thrown at crates/common/src/component.rs:715

}

/// Releases subscriptions for a component in the global registry.
///
/// This is used when retiring a component whose earlier `on_dispose` failed after the framework
/// left its registration intact.
///
/// # Errors
///
/// - Returns an error if the component is not found.
/// - Returns an error if the component is already borrowed.
pub fn release_component_subscriptions(id: &Ustr) -> anyhow::Result<()> {
    let component_ref = with_component_registry(|registry| {
        let component_ref = registry
            .get(id)
            .ok_or_else(|| anyhow::anyhow!("Component '{id}' not found in global registry"))?;

        if !registry.try_borrow(*id) {
            anyhow::bail!(
                "Component '{id}' is already mutably borrowed. \
                 This would create aliasing mutable references (undefined behavior)."
            );
        }

        Ok::<_, anyhow::Error>(component_ref)
    })?;

    let _guard = BorrowGuard::new(*id);

    // SAFETY: Borrow tracking ensures exclusive access
    unsafe {
        let component = &mut *component_ref.get();
        component.release_subscriptions();
    }

    Ok(())
}

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Check that the component was created through the factory/registration path that inserts it into the global registry before disposal.
  2. Guard against double disposal: track disposed component IDs and skip release_component_subscriptions if already released.
  3. Verify the ID being passed is the component's own ID (UUID4), not a stale or hand-constructed value.
  4. If teardown follows a failed init, ensure partial-failure cleanup only releases components that completed registration.

Example fix

// before
component.unregister_all_subscriptions();
dispose_registered_component(&component_id);

// after
if with_component_registry(|r| r.get(component_id).is_some()) {
    dispose_registered_component(&component_id);
} else {
    log::debug!("component {component_id} not registered; skipping disposal");
}
Defensive patterns

Strategy: try-catch

Validate before calling

let registered = with_component_registry(|r| r.get(&component_id).is_some());
if !registered {
    // skip disposal or log a warning
}

Type guard

fn is_registered(id: &ComponentId) -> bool {
    with_component_registry(|r| r.get(*id).is_some())
}

Try / catch

match release_component_subscriptions(&component_id) {
    Ok(_) => {}
    Err(e) if e.to_string().contains("not found in global registry") => {
        log::warn!("component {} already absent; ignoring", component_id);
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling dispose_registered_component -> release_component_subscriptions with a Component ID that was never inserted via the registry's registration path, was already removed, or whose ID string/UUID does not match any registered component (double-dispose, cloned stale ID, wrong actor/node).

Common situations: Double-disposal of the same component during shutdown; tearing down a node after a partial init failure where the component was never registered; reusing IDs across node restarts; copying component IDs from logs/config that belong to a different trader instance.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/1f1e7ff8f302ae97. Report an issue: GitHub.