nautechsystems/nautilus_trader · error

Failed to send query index_order_clients to database…

Error message

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

What it means

index_order_clients batches (ClientOrderId, ClientId) claims into DatabaseQuery::IndexOrderClients and sends them over self.tx to the database message handler; a send failure is wrapped in this error. An empty claims slice returns Ok early, so the only failure is a closed channel — the handler task has been dropped. The mapping is never persisted when this fires.

Solutions

  1. Confirm the cache handler task is alive before index updates
  2. Rebuild the adapter if it was shut down; do not reuse closed instances
  3. Fix the handler's original failure from logs
  4. Treat this as critical in live trading: order→client mappings lost here affect later lookups
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = cache.index_order_clients(&claims) {
    tracing::error!("order-client indexing failed: {e:#}");
    return Err(e.into());
}

Prevention

When it happens

Trigger: Calling index_order_clients with a non-empty claims slice after the handler task exited (shutdown, abort, or handler init failure).

Common situations: Adapter shutdown racing with execution engine index updates; handler crash from a prior failed query; stale adapter references after reconnect.

Related errors


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

Appendix: source

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

        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}"
            )
        })
    }

    fn update_actor(
        &self,
        actor_id: &ActorId,
        _state: &AHashMap<String, Bytes>,
    ) -> anyhow::Result<()> {
        anyhow::bail!("update_actor not implemented for PostgreSQL cache adapter: {actor_id}")
    }

    fn update_strategy(
        &self,
        strategy_id: &StrategyId,
        _state: &AHashMap<String, Bytes>,
    ) -> anyhow::Result<()> {

View on GitHub (pinned to 18893faf8b)