{"record":{"id":"212d2b719fe070f5","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-binance-spot-session-generation","errorCode":null,"errorMessage":"Failed to start Binance Spot session generation: {e}","messagePattern":"Failed to start Binance Spot session generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":870,"sourceCode":"        {\n            return Ok(());\n        }\n\n        if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {\n            self.teardown_partial_connect().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 Spot task generation: {e}\")\n            })?;\n        }\n\n        if !self.session_tasks.is_open() {\n            self.await_session_tasks().await?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Binance Spot session generation: {e}\")\n            })?;\n        }\n        let ws_trading_client = self.ws_trading_client.clone();\n        let ws_user_data_client = Arc::clone(&self.ws_user_data_client);\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                if let Some(client) = ws_trading_client {\n                    client.begin_shutdown();\n                }\n\n                if let Some(client) = ws_user_data_client.lock().as_ref() {\n                    client.begin_shutdown();\n                }\n            });\n\n        let ws_setup_timeout = Duration::from_millis(self.config.ws_trading_setup_timeout_ms);\n\n        // Load instruments if not already done","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/execution.rs#L852-L888","documentation":"Wraps a failure from `session_tasks.start_generation()` while connecting the Binance Spot execution client. The client awaits any in-flight session tasks, then tries to begin a new WebSocket session generation; if the task-group manager refuses (e.g. group is in a stopping/failed state), the underlying error is rethrown with this Binance Spot prefix.","triggerScenarios":"Calling `connect()` when the session task group has been stopped or previously errored, or when a previous generation's shutdown has not fully completed so `start_generation` rejects.","commonSituations":"Reconnecting after a network drop while old tasks are still tearing down; calling connect twice; a prior session error left the TaskGroup in a terminal state.","solutions":["Ensure `disconnect()`/`await_session_tasks()` fully completes before reconnecting.","Avoid calling `connect()` twice on the same client instance; recreate the client instead.","Inspect the inner error (`{e}` in the message) for the actual TaskGroup failure cause.","Retry connect with backoff if the previous generation is still shutting down."],"exampleFix":"// before\nself.session_tasks.start_generation().map_err(|e| {\n    anyhow::anyhow!(\"Failed to start Binance Spot session generation: {e}\")\n})?;\n// after\nif self.session_tasks.is_open() {\n    self.session_tasks.stop_generation().await?;\n}\nself.await_session_tasks().await?;\nself.session_tasks.start_generation().map_err(|e| {\n    anyhow::anyhow!(\"Failed to start Binance Spot session generation: {e}\")\n})?;","handlingStrategy":"retry","validationCode":"if !client.is_connected() && client.session_tasks_state() == TaskState::Stopped { /* safe to connect */ }","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"session generation\") => tokio::time::sleep(Duration::from_secs(2)).await, // retry after teardown\n    other => other?,\n}","preventionTips":["Never call connect() twice on one client instance","Always await disconnect()/session teardown before reconnecting","Log and inspect the inner TaskGroup error"],"tags":["websocket","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"}