{"record":{"id":"8f4ae7a4ab5e42ca","repo":"nautechsystems/nautilus_trader","slug":"betfair-execution-shutdown-failed","errorCode":null,"errorMessage":"Betfair execution shutdown failed: {}","messagePattern":"Betfair execution shutdown failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/execution.rs","lineNumber":575,"sourceCode":"        self.http_client.disconnect().await;\n        let (session_result, pending_result) =\n            tokio::join!(self.await_session_tasks(), self.await_pending_tasks());\n        self.core.set_disconnected();\n        self.clear_resync_state();\n\n        if let Err(e) = session_result {\n            self.shutdown_errors.push(e.to_string());\n        }\n\n        if let Err(e) = pending_result {\n            self.shutdown_errors.push(e.to_string());\n        }\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!(\"Betfair execution shutdown failed: {}\", errors.join(\"; \"))\n        }\n    }\n\n    #[expect(clippy::too_many_arguments)]\n    fn create_ocm_handler(\n        emitter: ExecutionEventEmitter,\n        account_id: AccountId,\n        currency: Currency,\n        ocm_state: Arc<Mutex<OcmState>>,\n        data_sender: tokio::sync::mpsc::UnboundedSender<DataEvent>,\n        market_ids_filter: Option<ahash::AHashSet<String>>,\n        ignore_external_orders: bool,\n        reconnect_tx: tokio::sync::mpsc::UnboundedSender<u64>,\n        queued_generation: Arc<AtomicU64>,\n        pending_resync: Arc<AtomicBool>,\n        reconciliation_gate: Arc<ReconciliationGate>,\n        replay_buffer: Arc<Mutex<Vec<ReceivedOcm>>>,\n        account_refresh_tx: tokio::sync::mpsc::UnboundedSender<()>,","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/execution.rs#L557-L593","documentation":"Analogous to the data client: teardown_partial_connect in the Betfair execution client aggregates errors from cancelling/joining its tasks (order streams, handlers) and bails with this message when teardown of a partially connected client produced any errors.","triggerScenarios":"connect() failure or disconnect() where execution-client background tasks fail to shut down cleanly, appending entries to shutdown_errors.","commonSituations":"TLS/stream failure during connect leaving the order stream task alive; disconnect raced with an in-flight order stream message; runtime dropped before tasks finished.","solutions":["Read the aggregated errors to find the offending task and address its root cause","Await disconnect() to completion on a live runtime before dropping the client","Retry the connect cycle; if persistent, capture logs of the failing task"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match exec_client.disconnect().await {\n    Err(e) if e.to_string().contains(\"shutdown failed\") => warn!(\"teardown issues: {e:#}\"),\n    other => other?,\n}","preventionTips":["Gracefully stop the execution client before runtime shutdown","Reconnect after full disconnect rather than reusing a partially connected client","Capture per-task logs to identify which handler fails teardown"],"tags":["betfair","shutdown","lifecycle","execution"],"backgroundTag":"shutdown-failure","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"}