{"record":{"id":"db39f9820fce8e6c","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-bybit-task-generation-e","errorCode":null,"errorMessage":"Failed to start Bybit task generation: {e}","messagePattern":"Failed to start Bybit task generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/execution.rs","lineNumber":738,"sourceCode":"        self.product_types().contains(&product_type)\n            && Self::provides_bulk_position_coverage_for_product_type(product_type)\n    }\n\n    async fn connect(&mut self) -> anyhow::Result<()> {\n        if self.core.is_connected() && self.pending_tasks.is_open() && self.session_tasks.is_open()\n        {\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\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Bybit task generation: {e}\"))?;\n        }\n\n        if !self.session_tasks.is_open() {\n            self.await_session_tasks().await?;\n            self.session_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Bybit session generation: {e}\"))?;\n        }\n        let http_client = self.http_client.clone();\n        let ws_private = self.ws_private.clone();\n        let ws_trade = self.ws_trade.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                http_client.cancel_all_requests();\n                ws_private.begin_shutdown();\n                ws_trade.begin_shutdown();\n            });\n","sourceCodeStart":720,"sourceCodeEnd":756,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/execution.rs#L720-L756","documentation":"connect() restarts the execution client's background task generation. If pending tasks were not open, it awaits their termination then calls start_generation(); a failure there is wrapped in this error to abort the connect sequence with context.","triggerScenarios":"Calling connect on BybitExecutionClient when the previous task generation is closed and starting a new one fails (e.g. runtime shut down, task group in bad state).","commonSituations":"Reconnecting after a fault where the tokio runtime or task group was already torn down; double-disconnect followed by connect.","solutions":["Inspect the inner error {e} for the task group failure cause","Create a fresh client instance instead of reusing a fully torn-down one","Ensure the tokio runtime is alive when calling connect","Check that disconnect completed cleanly before reconnecting"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure a live runtime and a cleanly disconnected client before connect():\n// assert client not connected and runtime handle available.","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Ok(()) => {}\n    Err(e) if e.to_string().contains(\"task generation\") => {\n        tracing::error!(\"connect failed starting task generation: {e}; recreating client\");\n        client = BybitExecutionClient::new(/* fresh deps */).await?;\n        client.connect().await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Do not reuse clients across tokio runtimes","Pair every disconnect with a fresh connect or a new client","Add integration tests for connect-disconnect-reconnect cycles"],"tags":["bybit","connect","async","task-management"],"backgroundTag":"internal-invariant-violation","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"}