{"record":{"id":"b363c819c4503308","repo":"nautechsystems/nautilus_trader","slug":"failed-to-terminate-ax-data-session-tasks-e","errorCode":null,"errorMessage":"Failed to terminate AX data session tasks: {e}","messagePattern":"Failed to terminate AX data session tasks: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/adapters/architect_ax/src/data.rs","lineNumber":366,"sourceCode":"        for cancellation in self.funding_rate_cancellations.values() {\n            cancellation.cancel();\n        }\n    }\n\n    async fn finish_all_tasks(&mut self) -> anyhow::Result<()> {\n        self.pending_tasks.begin_shutdown();\n        self.session_tasks.begin_shutdown();\n        let (pending_result, session_result) = tokio::join!(\n            self.pending_tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2)),\n            self.session_tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2)),\n        );\n        self.funding_rate_cancellations.clear();\n\n        pending_result.map_err(|e| anyhow::anyhow!(\"Failed to terminate AX data tasks: {e}\"))?;\n        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        }","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/data.rs#L348-L384","documentation":"finish_all_tasks also awaits session_tasks' graceful shutdown with 1s/2s timeouts. If a session task (e.g. session generation/keepalive task) fails to terminate in time, the error is wrapped as \"Failed to terminate AX data session tasks\". It indicates leftover session-level tasks after disconnect.","triggerScenarios":"Calling disconnect or teardown_partial_connect while AX session tasks remain alive past the finish_shutdown timeouts — e.g. a session task blocked on a hung websocket read.","commonSituations":"Disconnected network during shutdown; session task waiting on a server response that never arrives; task not observing the cancellation token.","solutions":["Force-abort session tasks if graceful shutdown repeatedly times out","Verify session tasks respect the cancellation token and wake promptly","Check network state; retry disconnect once connectivity is restored","Increase shutdown timeout durations if graceful wind-down legitimately needs more time"],"exampleFix":"// before\nself.session_tasks.finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n// after\nself.session_tasks.abort_all(); // then finish_shutdown for bookkeeping\nself.session_tasks.finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))","handlingStrategy":"try-catch","validationCode":"// Rust\n// ensure cancellation token is cancelled so session tasks can exit before shutdown await","typeGuard":null,"tryCatchPattern":"// Rust\nmatch client.disconnect().await {\n    Err(e) if e.to_string().contains(\"session tasks\") => log::warn!(\"session tasks hung; ignoring during shutdown\"),\n    other => other?,\n}","preventionTips":["Signal cancellation before disconnect so session tasks exit promptly","Keep session tasks free of unbounded blocking waits without cancellation checks","Log and continue on shutdown; leftovers are reclaimed when the client drops","If it recurs, force-abort tasks instead of awaiting graceful completion"],"tags":["shutdown","tasks","timeout","websocket"],"backgroundTag":"request-timeout","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"}