nautechsystems/nautilus_trader · error

Failed to send delete order command: {e}

Error message

Failed to send delete order command: {e}

What it means

delete_order queues a Delete command for the order record on an internal mpsc channel to the Redis writer task. This error means the channel send failed — the receiving task is gone (dropped its receiver), so no delete command can be delivered.

Source

Thrown at crates/infrastructure/src/redis/cache.rs:557

            Ok(()) => Ok(()),
            Err(e) => anyhow::bail!("{FAILED_TX_CHANNEL}: {e}"),
        }
    }

    /// Delete the given order from the database with full index cleanup.
    ///
    /// # Errors
    ///
    /// Returns an error if the command cannot be sent to the background task channel.
    pub fn delete_order(&self, client_order_id: &ClientOrderId) -> anyhow::Result<()> {
        let order_id_bytes = Bytes::from(client_order_id.to_string());

        // Delete the order itself
        let key = format!("{ORDERS}{REDIS_DELIMITER}{client_order_id}");
        let op = DatabaseCommand::new(DatabaseOperation::Delete, key, None);
        self.tx
            .send(op)
            .map_err(|e| anyhow::anyhow!("Failed to send delete order command: {e}"))?;

        // Delete from all order indexes
        let index_keys = [
            INDEX_ORDER_IDS,
            INDEX_ORDERS,
            INDEX_ORDERS_OPEN,
            INDEX_ORDERS_CLOSED,
            INDEX_ORDERS_EMULATED,
            INDEX_ORDERS_INFLIGHT,
        ];

        for index_key in &index_keys {
            let key = (*index_key).to_string();
            let payload = vec![order_id_bytes.clone()];
            let op = DatabaseCommand::new(DatabaseOperation::Delete, key, Some(payload));
            self.tx
                .send(op)
                .map_err(|e| anyhow::anyhow!("Failed to send delete order index command: {e}"))?;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Ensure the cache database connection is established and healthy before deleting orders; reconnect the cache if the writer task died.
  2. Do not call delete_order after cache shutdown / node teardown — check the node lifecycle.
  3. Check logs for earlier Redis connection errors that caused the writer task to exit, and fix the root connection issue.
  4. Recreate or restart the RedisCache adapter so a live receiver exists, then retry.
Defensive patterns

Strategy: try-catch

Try / catch

match cache.delete_order(&client_order_id) {
    Err(e) if e.to_string().contains("Failed to send delete order command") => {
        // writer task gone: reconnect cache or defer delete until node restarted
    }
    result => result?,
}

Prevention

When it happens

Trigger: Calling delete_order (or py_delete_order) after the Redis writer task that owns the receiving end of the command channel has been shut down or dropped.

Common situations: Deleting orders during or after node shutdown, after a database connection failure killed the writer task, or calling into a RedisCache whose background task was never started / already stopped.

Related errors


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