nautechsystems/nautilus_trader · error · anyhow::Error
Failed to start Databento task generation: {e}
Error message
Failed to start Databento task generation: {e} What it means
After terminating prior tasks, `connect` starts a new task generation via `task_handles.start_generation`. If spawning/starting the generation fails, connect aborts with this error. This means the client cannot establish its background Databento tasks.
Source
Thrown at crates/adapters/databento/src/data.rs:503
Ok(())
}
fn dispose(&mut self) -> anyhow::Result<()> {
log::debug!("Disposing");
self.stop()
}
async fn connect(&mut self) -> anyhow::Result<()> {
log::debug!("Connecting...");
if !self.task_handles.is_open() {
self.task_handles
.finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))
.await
.map_err(|e| anyhow::anyhow!("Failed to terminate Databento tasks: {e}"))?;
self.task_handles
.start_generation()
.map_err(|e| anyhow::anyhow!("Failed to start Databento task generation: {e}"))?;
self.cancellation_token = self.task_handles.cancellation_token();
}
self.is_connected.store(true, Ordering::Relaxed);
log::info!("Connected");
Ok(())
}
async fn disconnect(&mut self) -> anyhow::Result<()> {
log::debug!("Disconnecting...");
self.send_close_to_active_feeds();
self.clear_feed_channels();
self.task_handles.begin_shutdown();
let tasks_result = self
.task_handlesView on GitHub (pinned to 18893faf8b)
Solutions
- Confirm the client runs within a tokio runtime (use #[tokio::main] or a runtime handle)
- Retry connect(); if generation state is stuck, drop and recreate the client
- Check for previous shutdown failures (companion 'Failed to terminate Databento tasks' error) and fix that root cause first
- Inspect logs from TaskHandleTracker for the underlying spawn error
Example fix
// before
let client = DatabentoDataClient::new(...);
client.connect().await?; // fails outside runtime
// after
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let client = DatabentoDataClient::new(...);
client.connect().await
} Defensive patterns
Strategy: retry
Validate before calling
// ensure a tokio runtime exists before client use
let runtime = tokio::runtime::Handle::try_current()
.map_err(|_| anyhow::anyhow!("DatabentoDataClient requires a tokio runtime"))?; Try / catch
match client.connect().await {
Err(e) if e.to_string().contains("Failed to start Databento task generation") => {
eprintln!("dropping and recreating client after generation failure: {e}");
let client = rebuild_client()?;
client.connect().await?;
}
other => other?,
} Prevention
- Run the client inside an active tokio runtime
- Check for companion shutdown failures which leave generation state inconsistent
- Recreate the client rather than retrying connect() when generation start keeps failing
When it happens
Trigger: Calling connect() when `start_generation` fails — e.g. tokio runtime issues, spawn failures, or internal generation bookkeeping errors in TaskHandleTracker.
Common situations: Running the client outside a tokio runtime context, resource exhaustion preventing task spawn, or a corrupted/overlapping generation state after repeated reconnects.
Related errors
- Failed to terminate Databento tasks: {e}
- Failed to start Hyperliquid WebSocket handler task: {e}
- Failed to start Bybit task generation: {e}
- Failed to start Hyperliquid data session generation: {e}
- Failed to start Hyperliquid data task generation: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/30e1e2d7f869984d.
Report an issue: GitHub.