{"record":{"id":"51667dc0fdd9ef15","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-betfair-race-fatal-task-e","errorCode":null,"errorMessage":"Failed to register Betfair race fatal task: {e}","messagePattern":"Failed to register Betfair race fatal task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/data.rs","lineNumber":883,"sourceCode":"                            .push(BetfairStreamShutdown::Auxiliary(Arc::clone(&race_client)));\n\n                        let race_socket_control = self.race_socket_control.as_ref().map(Arc::clone);\n\n                        self.session_tasks\n                        .spawn(async move {\n                            if race_fatal_rx.recv().await.is_some() {\n                                log::error!(\n                                    \"Betfair race stream permanently disabled due to fatal error\"\n                                );\n                                race_client.close().await;\n\n                                if let Some(control) = race_socket_control {\n                                    control.deregister();\n                                }\n                            }\n                        })\n                        .map_err(|e| {\n                            anyhow::anyhow!(\"Failed to register Betfair race fatal task: {e}\")\n                        })?;\n\n                        log::debug!(\"Betfair race stream connected\");\n                    }\n                    Err(e) => {\n                        log::warn!(\"Betfair race stream connect failed: {e}\");\n\n                        if let Some(control) = &self.race_socket_control {\n                            control.deregister();\n                        }\n                        self.race_stream_client = None;\n                    }\n                }\n            }\n\n            if self.config.subscribe_cricket_data {\n                let cricket_config = BetfairStreamConfig {\n                    host: BETFAIR_RACE_STREAM_HOST.to_string(),","sourceCodeStart":865,"sourceCodeEnd":901,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/data.rs#L865-L901","documentation":"Registering the race stream's fatal-error monitoring task failed; the underlying error `{e}` is re-wrapped. This task watches the race stream for fatal conditions and triggers reconnection/shutdown; without it, a dead race stream would go undetected, so connect aborts.","triggerScenarios":"connect() -> after spawning the race stream task, .map_err wraps the registration (spawn onto a task group / stream shutdown registry) error. Typically occurs when the target TaskGroup is not open (shutdown in progress) or the spawn fails because the group was closed concurrently.","commonSituations":"Connect racing a disconnect that closed the task group; reconnect loops where the group generation ended before registration; internal spawn failure.","solutions":["Read the inner `{e}` for the exact registration failure (likely TaskGroup spawn error)","Ensure connect is not racing disconnect/shutdown on the same client","Retry connect so the race stream and its fatal watcher are registered in the same generation","Note: race stream connect failure itself is only a warning; only the fatal-task registration aborts — check whether the race stream endpoint actually connected"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// ensure no shutdown in progress before connect\nif client.is_shutting_down() { return Err(anyhow::anyhow!(\"connect during shutdown\")); }","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to register Betfair race fatal task\") => {\n        log::error!(\"race fatal watcher not registered: {e:#}\");\n        // retry connect; ensure disconnect() isn't running concurrently\n    }\n    other => other,\n}","preventionTips":["Never interleave connect and disconnect calls concurrently","Complete prior teardowns before reconnecting","Treat race-stream connect warnings separately from registration failures","Retry connect to re-register the fatal watcher in a fresh generation"],"tags":["task-group","race-stream","betfair","async"],"backgroundTag":"invalid-state-transition","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"}