{"record":{"id":"515aa9edbf0da033","repo":"nautechsystems/nautilus_trader","slug":"failed-to-finish-betfair-data-session-tasks-e","errorCode":null,"errorMessage":"Failed to finish Betfair data session tasks: {e}","messagePattern":"Failed to finish Betfair data session tasks: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/adapters/betfair/src/data.rs","lineNumber":228,"sourceCode":"\n    fn spawn_command<F>(&self, future: F)\n    where\n        F: std::future::Future<Output = ()> + Send + 'static,\n    {\n        if let Err(e) = self.command_tasks.spawn(future) {\n            log::warn!(\"Skipping Betfair data command after shutdown began: {e}\");\n        }\n    }\n\n    async fn finish_tasks(&self) -> anyhow::Result<()> {\n        let (session_result, command_result) = tokio::join!(\n            self.session_tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2)),\n            self.command_tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2)),\n        );\n        session_result\n            .map_err(|e| anyhow::anyhow!(\"Failed to finish Betfair data session tasks: {e}\"))?;\n        command_result\n            .map_err(|e| anyhow::anyhow!(\"Failed to finish Betfair data command tasks: {e}\"))?;\n        Ok(())\n    }\n\n    async fn prepare_task_groups(&mut self) -> anyhow::Result<()> {\n        if !self.session_tasks.is_open() || !self.command_tasks.is_open() {\n            self.teardown_partial_connect().await?;\n            self.session_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Betfair data session tasks: {e}\"))?;\n            self.command_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Betfair data command tasks: {e}\"))?;\n        }\n        Ok(())\n    }\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/data.rs#L210-L246","documentation":"During Betfair data-client teardown, finish_tasks awaits both session and command task groups' finish_shutdown and maps any error in the session group to this message. It means session-related spawned tasks did not shut down cleanly within the 1s/2s grace timeouts.","triggerScenarios":"Calling teardown_partial_connect -> finish_tasks when session tasks are hung, panicked, or fail to complete within Duration::from_secs(1)/from_secs(2) deadlines.","commonSituations":"Session tasks blocked on a stalled Betfair stream socket during disconnect; task panics from bad stream data; slow network keeping reads pending past the shutdown timeout.","solutions":["Check the wrapped {e} for whether tasks timed out or panicked","Ensure the stream socket is properly closed/aborted before finish_shutdown so session tasks can exit","Log and continue if this occurs during partial-teardown cleanup, since the client is being discarded anyway","Increase shutdown budgets if the network legitimately needs longer to drain"],"exampleFix":"// before\nsession_tasks.finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n// after (if slow networks are expected)\nsession_tasks.finish_shutdown(Duration::from_secs(5), Duration::from_secs(10))","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nif let Err(e) = finish_tasks().await {\n    // teardown path: log, don't mask the original disconnect error\n    tracing::warn!(\"betfair session tasks shutdown incomplete: {e:#}\");\n}","preventionTips":["Abort/cancel stream sockets before finish_shutdown so session tasks can exit promptly","Keep shutdown grace periods larger than your worst-case network stall","Avoid panics in session task bodies (validate stream data defensively)","Treat teardown errors as warnings during partial-connect cleanup"],"tags":["shutdown","async","tasks","betfair"],"backgroundTag":"task-did-not-stop-after-abort","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"}