{"record":{"id":"edd9f8b2429f4999","repo":"nautechsystems/nautilus_trader","slug":"joined-shutdown-errors-std-mem-take-mut-self-s-edd9f8","errorCode":null,"errorMessage":"joined shutdown errors (std::mem::take(&mut self.shutdown_errors).join(\"; \"))","messagePattern":"joined shutdown errors \\(std::mem::take\\(&mut self\\.shutdown_errors\\)\\.join\\(\"; \"\\)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/execution.rs","lineNumber":435,"sourceCode":"        if let Err(e) = self.ws_client.disconnect().await {\n            self.shutdown_errors\n                .push(format!(\"Derive WebSocket shutdown failed: {e}\"));\n        }\n        let (session_result, pending_result) =\n            tokio::join!(self.await_session_tasks(), self.await_pending_tasks());\n        self.core.set_disconnected();\n        self.is_connected.store(false, Ordering::Release);\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            anyhow::bail!(std::mem::take(&mut self.shutdown_errors).join(\"; \"));\n        }\n        Ok(())\n    }\n\n    fn start_ws_dispatch(\n        &self,\n        rx: tokio::sync::mpsc::UnboundedReceiver<DeriveWsMessage>,\n    ) -> anyhow::Result<()> {\n        let emitter = self.emitter.clone();\n        let account_id = self.core.account_id;\n        let clock = self.clock;\n        let cancellation = self.cancellation_token.clone();\n        let dispatch_state = self.dispatch_state.clone();\n        let reconciliation = self.reconciliation_context();\n        let is_connected = Arc::clone(&self.is_connected);\n        let session_spawner = self\n            .session_tasks\n            .spawner()","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/execution.rs#L417-L453","documentation":"teardown_partial_connect collects errors encountered while unwinding a partially completed connect (or during disconnect), accumulating them in self.shutdown_errors. If any accumulated, it joins them with '; ' and bails so no teardown failure is silently swallowed.","triggerScenarios":"connect() fails partway (e.g. auth WS fails after HTTP init) and cleanup steps (closing sessions, cancelling tasks) also fail; or disconnect() encounters errors while stopping multiple components.","commonSituations":"Network drops mid-connect so both the primary step and its cleanup fail; calling disconnect while WS tasks are already dead; cascading failures after credential rejection.","solutions":["Read the joined messages to identify the FIRST root-cause error (earliest in the '; '-joined string)","Fix the original connect failure (auth, network, config) — teardown errors are usually secondary","Check endpoint connectivity and retry connect after the network stabilizes","If disconnect errors persist, ensure components are idempotently stoppable"],"exampleFix":"// before (diagnose from joined string)\nErr(e) => eprintln!(\"{}\", e) // \"task join failed; ws close failed\"\n// after — handle root cause first\nif e.to_string().contains(\"auth\") { fix_credentials()?; }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = client.connect().await {\n    // first '; '-joined segment is the primary teardown error; root cause is usually earlier in connect logs\n    for part in e.to_string().split(\"; \") { log::error!(\"shutdown: {part}\"); }\n}","preventionTips":["Ensure WS/HTTP tasks are cancellable and close is idempotent","Handle network loss gracefully so teardown steps don't cascade","Retry connect after transient network failures instead of treating teardown errors as fatal root causes"],"tags":["rust","shutdown","cleanup","error-aggregation"],"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-14T05:17:10.506Z"}