{"record":{"id":"bde54aeb7b065b1d","repo":"nautechsystems/nautilus_trader","slug":"joined-shutdown-errors-std-mem-take-mut-self-s","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/data.rs","lineNumber":271,"sourceCode":"            self.shutdown_errors\n                .push(format!(\"Derive WebSocket shutdown failed: {e}\"));\n        }\n        let (session_result, pending_result) =\n            tokio::join!(self.join_session_tasks(), self.join_pending_tasks());\n        self.clear_subscription_state();\n        self.channel_subscriptions.clear_transitions();\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 spawn_stream_task(\n        &self,\n        mut rx: tokio::sync::mpsc::UnboundedReceiver<DeriveWsMessage>,\n    ) -> anyhow::Result<()> {\n        let ctx = WsMessageContext {\n            clock: self.clock,\n            data_sender: self.data_sender.clone(),\n            instruments: Arc::clone(&self.instruments),\n            active_book_delta_channels: Arc::clone(&self.active_book_delta_channels),\n            active_book_depth10_channels: Arc::clone(&self.active_book_depth10_channels),\n            active_ticker_channels: Arc::clone(&self.active_ticker_channels),\n            active_quote_subs: Arc::clone(&self.active_quote_subs),\n            active_trade_subs: Arc::clone(&self.active_trade_subs),\n            active_mark_subs: Arc::clone(&self.active_mark_subs),","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/data.rs#L253-L289","documentation":"Raised by `teardown_partial_connect` in the Derive data client when one or more pending connection tasks failed during teardown. Each failure string is accumulated in `shutdown_errors`, then all errors are joined with \"; \" and returned as a single aggregated error once the teardown completes.","triggerScenarios":"Calling connect() or disconnect() when spawned subscription/stream tasks fail to complete or error out while being awaited during partial-connection cleanup (e.g. a WebSocket task panicked, errored, or the HTTP init step failed mid-connect).","commonSituations":"Network outages or Derive API unavailability while connecting; auth failures mid-handshake leaving tasks to fail; disconnecting while streams are in an error state; seeing multiple underlying causes joined in one message.","solutions":["Read the joined messages in the error to identify which underlying task(s) failed and fix the root cause (network, auth, URL).","Check connectivity and Derive API availability, then retry connect().","Verify credentials/API URL configuration if the underlying errors mention auth or request failures.","Retry the disconnect()/connect() cycle; the error list is cleared via mem::take so a clean retry is possible."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Ok(()) => {},\n    Err(e) => {\n        // e may contain multiple causes joined by \"; \" — log all, retry after backoff\n        log::error!(\"Derive connect teardown errors: {e}\");\n        tokio::time::sleep(BACKOFF).await;\n        retry_connect();\n    }\n}","preventionTips":["Monitor the individual causes in the joined \"; \" message to fix root causes.","Check Derive API/WebSocket reachability before connecting.","Verify credentials and URLs before partial teardown-prone connects.","Implement reconnect with exponential backoff."],"tags":["websocket","connection","shutdown","aggregated-errors","derive"],"backgroundTag":"connection-refused","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"}