{"record":{"id":"7557d5643c1a7892","repo":"nautechsystems/nautilus_trader","slug":"std-mem-take-mut-self-shutdown-errors-join","errorCode":null,"errorMessage":"std::mem::take(&mut self.shutdown_errors).join(\"; \")","messagePattern":"std::mem::take\\(&mut self\\.shutdown_errors\\)\\.join\\(\"; \"\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/data.rs","lineNumber":383,"sourceCode":"        session_result\n            .map_err(|e| anyhow::anyhow!(\"Failed to terminate AX data session tasks: {e}\"))?;\n        Ok(())\n    }\n\n    async fn teardown_partial_connect(&mut self) -> anyhow::Result<()> {\n        self.abort_all_tasks();\n\n        if let Err(e) = self.ws_client.close().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n\n        if let Err(e) = self.finish_all_tasks().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n        self.is_connected.store(false, Ordering::Release);\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\n#[async_trait(?Send)]\nimpl DataClient for AxDataClient {\n    fn client_id(&self) -> ClientId {\n        self.client_id\n    }\n\n    fn venue(&self) -> Option<Venue> {\n        Some(*AX_VENUE)\n    }\n\n    fn start(&mut self) -> anyhow::Result<()> {\n        log::debug!(\"Starting {}\", self.client_id);\n        Ok(())","sourceCodeStart":365,"sourceCodeEnd":401,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/data.rs#L365-L401","documentation":"During AX data-client connect, `teardown_partial_connect` runs finish_all_tasks and other cleanup; any errors accumulated into self.shutdown_errors are drained and reported as a single joined bail. It surfaces failure to cleanly tear down a partially established connection, masking the original connect error.","triggerScenarios":"connect() on AXDataClient fails partway (websocket handshake error, task spawn failure) and one or more teardown steps (finish_all_tasks, closing streams) also error.","commonSituations":"AX gateway unreachable or TLS problems causing partial connect; shutdown racing an in-flight task; network interruption during startup.","solutions":["Read all ';'-joined messages in the error: the first usually points at the root connect cause, later ones at teardown side effects","Verify network/TLS reachability of the AX gateway and credentials, then retry connect","Inspect finish_all_tasks error sources (task panics, channel closes) if teardown messages dominate"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-check gateway reachability before connect\nTcpStream::connect((host, port)).await.context(\"AX gateway unreachable\")?;","typeGuard":null,"tryCatchPattern":"match data_client.connect().await {\n    Ok(()) => {},\n    Err(e) => {\n        log::error!(\"AX data connect failed: {e}\"); // includes joined teardown errors\n        backoff_retry(connect, max_attempts = 3).await?;\n    }\n}","preventionTips":["Verify gateway host/port/TLS and credentials in config before starting","Monitor the first error segment in joined teardown messages for the root cause","Add readiness checks so connect is not attempted while the network is known down"],"tags":["rust","adapter","connection","lifecycle","websocket"],"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"}