{"record":{"id":"30e1e2d7f869984d","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-databento-task-generation-e","errorCode":null,"errorMessage":"Failed to start Databento task generation: {e}","messagePattern":"Failed to start Databento task generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/data.rs","lineNumber":503,"sourceCode":"        Ok(())\n    }\n\n    fn dispose(&mut self) -> anyhow::Result<()> {\n        log::debug!(\"Disposing\");\n        self.stop()\n    }\n\n    async fn connect(&mut self) -> anyhow::Result<()> {\n        log::debug!(\"Connecting...\");\n\n        if !self.task_handles.is_open() {\n            self.task_handles\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to terminate Databento tasks: {e}\"))?;\n            self.task_handles\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Databento task generation: {e}\"))?;\n            self.cancellation_token = self.task_handles.cancellation_token();\n        }\n\n        self.is_connected.store(true, Ordering::Relaxed);\n\n        log::info!(\"Connected\");\n        Ok(())\n    }\n\n    async fn disconnect(&mut self) -> anyhow::Result<()> {\n        log::debug!(\"Disconnecting...\");\n\n        self.send_close_to_active_feeds();\n        self.clear_feed_channels();\n        self.task_handles.begin_shutdown();\n\n        let tasks_result = self\n            .task_handles","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/data.rs#L485-L521","documentation":"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.","triggerScenarios":"Calling connect() when `start_generation` fails — e.g. tokio runtime issues, spawn failures, or internal generation bookkeeping errors in TaskHandleTracker.","commonSituations":"Running the client outside a tokio runtime context, resource exhaustion preventing task spawn, or a corrupted/overlapping generation state after repeated reconnects.","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"],"exampleFix":"// before\nlet client = DatabentoDataClient::new(...);\nclient.connect().await?; // fails outside runtime\n// after\n#[tokio::main]\nasync fn main() -> anyhow::Result<()> {\n    let client = DatabentoDataClient::new(...);\n    client.connect().await\n}","handlingStrategy":"retry","validationCode":"// ensure a tokio runtime exists before client use\nlet runtime = tokio::runtime::Handle::try_current()\n    .map_err(|_| anyhow::anyhow!(\"DatabentoDataClient requires a tokio runtime\"))?;","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to start Databento task generation\") => {\n        eprintln!(\"dropping and recreating client after generation failure: {e}\");\n        let client = rebuild_client()?;\n        client.connect().await?;\n    }\n    other => other?,\n}","preventionTips":["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"],"tags":["databento","connect","task-spawn","async"],"backgroundTag":"module-init-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}