{"record":{"id":"c2aae9c65906bc4f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-binance-futures-task-generation","errorCode":null,"errorMessage":"Failed to start Binance Futures task generation: {e}","messagePattern":"Failed to start Binance Futures task generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/futures/execution.rs","lineNumber":1692,"sourceCode":"\n    fn get_account(&self) -> Option<AccountAny> {\n        self.core.cache().account_owned(&self.core.account_id)\n    }\n\n    async fn connect(&mut self) -> anyhow::Result<()> {\n        if self.core.is_connected() && self.session_tasks.is_open() && self.pending_tasks.is_open()\n        {\n            return Ok(());\n        }\n\n        if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {\n            self.disconnect().await?;\n        }\n\n        if !self.pending_tasks.is_open() {\n            self.await_pending_tasks().await?;\n            self.pending_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Binance Futures task generation: {e}\")\n            })?;\n        }\n\n        if !self.session_tasks.is_open() {\n            self.await_session_tasks().await?;\n            self.await_dispatch_task().await?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Binance Futures session generation: {e}\")\n            })?;\n        }\n\n        self.cancellation_token = CancellationToken::new();\n        let cancellation_token = self.cancellation_token.clone();\n        let ws_client = Arc::clone(&self.ws_client);\n        let ws_trading_client = self.ws_trading_client.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                cancellation_token.cancel();","sourceCodeStart":1674,"sourceCodeEnd":1710,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/futures/execution.rs#L1674-L1710","documentation":"Raised in BinanceFuturesExecutionClient::connect when the pending-tasks tokio TaskGroup fails to start a new generation. The client uses task groups to track background tasks; if awaiting or starting the pending-task generation fails (e.g. the group was already shut down or a task panicked during spawn/generation start), connect aborts with this wrapped error. It indicates the client could not set up its internal task infrastructure.","triggerScenarios":"Calling connect() when pending_tasks group is not open and start_generation() returns an error — typically after a previous disconnect shut the group down improperly, a task in the group panicked, or the runtime is shutting down while connect is in flight.","commonSituations":"Reconnecting a live-node client after a fault without a clean disconnect, stopping the node while connect() is still running, or a panic inside a previously spawned pending task poisoning the group generation.","solutions":["Call disconnect() (or recreate the client) before reconnecting so task groups are fully torn down and can start a fresh generation.","Check logs above the error for a panicking background task and fix the underlying panic.","Ensure the tokio runtime is alive and not being shut down while connect() is awaited.","If reproducible, capture the inner error `{e}` for the concrete cause and report/fix that root task failure."],"exampleFix":"// before\nclient.connect().await?; // reconnect after fault\n\n// after\nclient.disconnect().await?;\nclient.connect().await?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"task generation\") => {\n        client.disconnect().await?;\n        client.connect().await?;\n    }\n    r => r?,\n}","preventionTips":["Always disconnect cleanly before reconnecting","Serialize connect/disconnect calls; never run them concurrently","Investigate task panics in logs — they poison task groups"],"tags":["binance","tokio","task-group","connection","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}