{"record":{"id":"63b274e4fe4b5a9d","repo":"nautechsystems/nautilus_trader","slug":"std-mem-take-mut-self-shutdown-errors-join-63b274","errorCode":null,"errorMessage":"std::mem::take(&mut self.shutdown_errors).join(\"; \")","messagePattern":"std::mem::take\\(&mut self\\.shutdown_errors\\)\\.join\\(\"; \"\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":991,"sourceCode":"        Ok(())\n    }\n\n    async fn finish_shutdown(&mut self) -> anyhow::Result<()> {\n        if let Err(e) = self\n            .ws_client\n            .disconnect()\n            .await\n            .context(\"failed to disconnect dYdX websocket\")\n        {\n            self.shutdown_errors.push(e.to_string());\n        }\n\n        if let Err(e) = self.finish_tasks().await {\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    async fn teardown_partial_connect(&mut self) -> anyhow::Result<()> {\n        self.begin_pending_shutdown();\n        self.session_tasks.begin_shutdown();\n        self.ws_client.begin_shutdown();\n        let shutdown_result = self.finish_shutdown().await;\n        self.core.set_disconnected();\n        shutdown_result\n    }\n\n    fn send_modify_rejected(\n        &self,\n        strategy_id: StrategyId,\n        instrument_id: InstrumentId,\n        client_order_id: ClientOrderId,","sourceCodeStart":973,"sourceCodeEnd":1009,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L973-L1009","documentation":"Mirroring the data client, the dYdX execution client collects errors from its session tasks during shutdown; finish_shutdown drains shutdown_errors and bails with all messages joined by '; '. It reports any task that failed to finish cleanly when stopping the execution engine.","triggerScenarios":"Calling finish_shutdown (via prepare_task_groups or teardown_partial_connect) when any session task (WebSocket handler, order/stream tasks) ended with an Err or panic during shutdown.","commonSituations":"Live WebSocket failing during client stop; order submission task erroring concurrently with shutdown; forced disconnects from the exchange mid-teardown.","solutions":["Inspect the joined error strings to find the failing task's root cause","Check connectivity/credentials if the WebSocket task is the failing one","Log and handle shutdown errors gracefully; retry disconnect if the transport was already broken"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.disconnect().await {\n    Ok(()) => {},\n    Err(e) => {\n        for msg in e.to_string().split(\"; \") {\n            log::warn!(\"execution shutdown task error: {msg}\");\n        }\n    }\n}","preventionTips":["Watch session task health (WebSocket liveness) to catch failures early","Ensure orders in flight are reconciled before shutdown to avoid task errors"],"tags":["rust","dydx-exchange","shutdown","task-error","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-14T05:17:10.506Z"}