nautechsystems/nautilus_trader · error

Failed to send query index_order_position to database messag

Error message

Failed to send query index_order_position to database message handler: {e}

What it means

index_order_position sends DatabaseQuery::IndexOrderPosition (a ClientOrderId→PositionId mapping) over the cache's mpsc channel to the database message handler; send failure becomes this error. The send can only fail if the handler's receiver was dropped, meaning the background persistence task is gone. No lookup or write has happened yet — the index command never reached the database layer.

Source

Thrown at crates/infrastructure/src/sql/cache.rs:1230

        Ok(rx.recv()?)
    }

    fn index_venue_order_id(
        &self,
        _client_order_id: ClientOrderId,
        _venue_order_id: VenueOrderId,
    ) -> anyhow::Result<()> {
        todo!()
    }

    fn index_order_position(
        &self,
        client_order_id: ClientOrderId,
        position_id: PositionId,
    ) -> anyhow::Result<()> {
        let query = DatabaseQuery::IndexOrderPosition(client_order_id, position_id);
        self.tx.send(query).map_err(|e| {
            anyhow::anyhow!(
                "Failed to send query index_order_position to database message handler: {e}"
            )
        })
    }

    fn index_order_clients(&self, claims: &[(ClientOrderId, ClientId)]) -> anyhow::Result<()> {
        if claims.is_empty() {
            return Ok(());
        }

        let query = DatabaseQuery::IndexOrderClients(claims.to_vec());
        self.tx.send(query).map_err(|e| {
            anyhow::anyhow!(
                "Failed to send query index_order_clients to database message handler: {e}"
            )
        })
    }

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Ensure the database adapter and handler task are running before indexing operations
  2. Recreate the adapter after shutdown rather than writing through stale handles
  3. Investigate the handler's exit reason in logs and fix the root cause
  4. Fail fast on this error in execution paths — an unindexed order/position link can break position reporting
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = cache.index_order_position(&client_order_id, &position_id) {
    // channel to DB handler is closed — persistence layer is down
    tracing::error!("order-position indexing failed: {e:#}");
    return Err(e.into());
}

Prevention

When it happens

Trigger: Calling index_order_position when the handler task has exited (adapter shutdown, aborted task, handler died at init), typically while an execution engine still indexes order/position links.

Common situations: Cache adapter torn down while a trading node keeps running; handler panicked earlier leaving the channel closed; reusing an adapter from a previous async runtime context.

Related errors


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