{"record":{"id":"7242b49b9eddd6bc","repo":"nautechsystems/nautilus_trader","slug":"architect-ax-data-websocket-handler-failed-error","errorCode":null,"errorMessage":"Architect AX data WebSocket handler failed: {error}","messagePattern":"Architect AX data WebSocket handler failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/websocket/data/client.rs","lineNumber":1078,"sourceCode":"        self.cancellation_token.load().cancel();\n        let _ = self.send_cmd(HandlerCommand::Disconnect).await;\n        tokio::time::sleep(Duration::from_millis(50)).await;\n        self.signal.store(true, Ordering::Release);\n\n        let outcome = self\n            .task_handle\n            .finish(Duration::from_secs(2), Duration::from_secs(2))\n            .await;\n\n        *self.reconnect_headers.lock() = None;\n\n        if let Some(control) = &self.socket_control {\n            control.deregister();\n        }\n\n        match outcome {\n            None | Some(TaskJoinOutcome::Completed(()) | TaskJoinOutcome::Aborted) => Ok(()),\n            Some(TaskJoinOutcome::Failed(error)) => Err(anyhow::anyhow!(\n                \"Architect AX data WebSocket handler failed: {error}\"\n            )),\n            Some(TaskJoinOutcome::Incomplete) => Err(anyhow::anyhow!(\n                \"Architect AX data WebSocket handler did not stop after abort\"\n            )),\n        }\n    }\n\n    async fn send_cmd(&self, cmd: HandlerCommand) -> AxWsResult<()> {\n        let guard = self.cmd_tx.read().await;\n        guard\n            .send(cmd)\n            .map_err(|e| AxWsClientError::ChannelError(e.to_string()))\n    }\n}\n\nimpl Drop for AxMdWebSocketClient {\n    fn drop(&mut self) {","sourceCodeStart":1060,"sourceCodeEnd":1096,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/websocket/data/client.rs#L1060-L1096","documentation":"Returned by the Architect AX data WebSocket client's close(). After aborting, it joins the handler task and maps the outcome: if the handler task ended in an error (TaskJoinOutcome::Failed), close() propagates that error wrapped in this anyhow message instead of returning Ok.","triggerScenarios":"Calling DataWebSocketClient::close() while the internal data handler task has terminated with an error — e.g. the handler failed on a malformed inbound frame, a send-channel error, or an unexpected stream termination rather than completing or being aborted cleanly.","commonSituations":"The remote feed dropped the connection mid-session with a handler-level error; a code bug in the message handler caused a panic/result error; shutdown raced with an already-failed handler in tests or teardown.","solutions":["Inspect the inner handler error (the {error} payload) to find the root cause before looking at close() itself","Check server/connectivity logs around shutdown time for why the handler task failed","Ensure close() is only called during teardown and handle the returned Err as a non-fatal shutdown warning if the session is ending anyway","Update the adapter if the root cause is a handler bug on specific message types"],"exampleFix":"// before\nclient.close().await?; // may fail with handler error\n// after\nif let Err(e) = client.close().await {\n    tracing::warn!(\"data ws close: {e:#}\"); // handler already failed; teardown continues\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch client.close().await {\n    Ok(()) => {},\n    Err(e) => tracing::warn!(\"data ws handler failed on close: {e:#}\"),\n}","preventionTips":["Ensure the handler task handles stream errors gracefully instead of returning Err on transient failures","Close the client during normal teardown, not after known handler failures you haven't diagnosed","Keep cancellation checks in the handler loop so aborts are honored","Log the inner error immediately — it names the root cause"],"tags":["websocket","async","shutdown","rust"],"backgroundTag":"background-task-failed","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"}