{"record":{"id":"f18966be54ab31f9","repo":"nautechsystems/nautilus_trader","slug":"bybit-execution-shutdown-failed","errorCode":null,"errorMessage":"Bybit execution shutdown failed: {}","messagePattern":"Bybit execution shutdown failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bybit/src/execution.rs","lineNumber":315,"sourceCode":"            self.shutdown_errors\n                .push(format!(\"trade WebSocket shutdown failed: {e}\"));\n        }\n        self.dispatch_state.clear_repay_sender();\n\n        if let Err(e) = self.await_session_tasks().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n\n        if let Err(e) = self.await_pending_tasks().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n        self.core.set_disconnected();\n\n        if self.shutdown_errors.is_empty() {\n            Ok(())\n        } else {\n            let errors = std::mem::take(&mut self.shutdown_errors);\n            anyhow::bail!(\"Bybit execution shutdown failed: {}\", errors.join(\"; \"))\n        }\n    }\n\n    /// Polls the cache until the account is registered or timeout is reached.\n    async fn await_account_registered(&self, timeout_secs: f64) -> anyhow::Result<()> {\n        let account_id = self.core.account_id;\n\n        if self.core.cache().account(&account_id).is_some() {\n            log::info!(\"Account {account_id} registered\");\n            return Ok(());\n        }\n\n        let start = Instant::now();\n        let timeout = Duration::from_secs_f64(timeout_secs);\n        let interval = Duration::from_millis(10);\n\n        loop {\n            tokio::time::sleep(interval).await;","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bybit/src/execution.rs#L297-L333","documentation":"Aggregated error raised when the Bybit execution client fails to cleanly tear down during connect/disconnect. Individual shutdown step failures are collected in shutdown_errors and joined into a single bail after set_disconnected().","triggerScenarios":"Calling connect() or disconnect() when teardown steps fail (e.g. WebSocket close errors, HTTP unsubscribe/cancel failures recorded during teardown).","commonSituations":"Network partitions during disconnect; venue returning errors on final REST calls; stale WebSocket connections that cannot be closed gracefully.","solutions":["Inspect the joined error message to identify which teardown step failed","Check network connectivity and Bybit API status before reconnecting","Retry disconnect(); the client should still be marked disconnected so a fresh connect is possible","Enable debug logging on the Bybit execution client to see per-step shutdown failures"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match exec_client.disconnect().await {\n    Err(e) if e.to_string().starts_with(\"Bybit execution shutdown failed\") => {\n        tracing::warn!(\"shutdown partial failure: {e}; forcing reconnect\");\n        // client is already marked disconnected; proceed with a fresh connect\n        exec_client.connect().await?;\n    }\n    r => r?,\n}","preventionTips":["Check Bybit API status and network before/after long-running sessions","Log shutdown_errors details via debug logging to find the failing teardown step","Treat a partial shutdown as recoverable — the client sets itself disconnected regardless"],"tags":["bybit","execution","shutdown","disconnect","websocket"],"backgroundTag":"http-request-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"}