nautechsystems/nautilus_trader · error · anyhow::Error

Failed to send command to dataset {dataset}: {e}

Error message

Failed to send command to dataset {dataset}: {e}

What it means

This error is raised when sending a HandlerCommand::SetPricePrecision to the databento subscription command channel fails. The channel to the handler command loop is closed or full, so the precision update cannot be delivered before subscribing. It wraps the underlying mpsc send error and identifies the target dataset.

Source

Thrown at crates/adapters/databento/src/data.rs:1446

        .map(dbn::Schema::as_str)
        .collect::<Vec<_>>()
        .join(", ");
    anyhow::bail!(
        "Invalid `{SCHEMA_PARAM}` '{}'. Must be one of: {allowed}",
        schema.as_str()
    );
}

fn send_subscription_commands(
    tx: &tokio::sync::mpsc::UnboundedSender<HandlerCommand>,
    dataset: &str,
    price_precision: Option<(Symbol, u8)>,
    subscription: Subscription,
    start_after_subscribe: bool,
) -> anyhow::Result<()> {
    if let Some((symbol, precision)) = price_precision {
        tx.send(HandlerCommand::SetPricePrecision(symbol, precision))
            .map_err(|e| anyhow::anyhow!("Failed to send command to dataset {dataset}: {e}"))?;
    }

    tx.send(HandlerCommand::Subscribe(subscription))
        .map_err(|e| anyhow::anyhow!("Failed to send command to dataset {dataset}: {e}"))?;

    if start_after_subscribe {
        tx.send(HandlerCommand::Start)
            .map_err(|e| anyhow::anyhow!("Failed to send command to dataset {dataset}: {e}"))?;
    }

    Ok(())
}

#[cfg(test)]
mod tests {
    use std::path::PathBuf;

    use nautilus_common::live::runner::replace_data_event_sender;

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Verify the client's command-handling task is still running before calling subscribe APIs
  2. Retry the subscription after re-establishing the client connection
  3. Log and surface the dataset name and underlying send error for diagnosis
  4. Check for races where the subscription stream is closed concurrently with subscribe calls

Example fix

// before
client.subscribe(...).map_err(|e| anyhow!("subscribe failed: {e}"))?;
// after
if !client.is_connected() { client.reconnect().await?; }
client.subscribe(...).map_err(|e| anyhow!("subscribe failed: {e}"))?;
Defensive patterns

Strategy: validation

Validate before calling

// Rust
if tx.is_closed() { anyhow::bail!("command channel closed for {dataset}"); }

Try / catch

// Rust
if let Err(e) = send_subscription_to_dataset(...).await {
    error!("{e:#}");
}

Prevention

When it happens

Trigger: Calling send_subscription_to_dataset (via send_subscription_commands) with Some(price_precision) while the command channel receiver has been dropped, or when the bounded channel buffer is full at send time.

Common situations: Subscribing with a price precision after the data handler's command loop has already shut down (client disconnect/reconnect race); heavy subscribe bursts overflowing the bounded command channel; tests simulating closed channels.

Related errors


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