{"record":{"id":"4acb8e1c555e9fd6","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-betfair-cricket-fatal-task-e","errorCode":null,"errorMessage":"Failed to register Betfair cricket fatal task: {e}","messagePattern":"Failed to register Betfair cricket fatal task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/data.rs","lineNumber":968,"sourceCode":"\n                        let cricket_socket_control =\n                            self.cricket_socket_control.as_ref().map(Arc::clone);\n\n                        self.session_tasks\n                        .spawn(async move {\n                            if cricket_fatal_rx.recv().await.is_some() {\n                                log::error!(\n                                    \"Betfair cricket stream permanently disabled due to fatal error\"\n                                );\n                                cricket_client.close().await;\n\n                                if let Some(control) = cricket_socket_control {\n                                    control.deregister();\n                                }\n                            }\n                        })\n                        .map_err(|e| {\n                            anyhow::anyhow!(\"Failed to register Betfair cricket fatal task: {e}\")\n                        })?;\n\n                        log::debug!(\"Betfair cricket stream connected\");\n                    }\n                    Err(e) => {\n                        log::warn!(\"Betfair cricket stream connect failed: {e}\");\n\n                        if let Some(control) = &self.cricket_socket_control {\n                            control.deregister();\n                        }\n                        self.cricket_stream_client = None;\n                    }\n                }\n            }\n\n            let keep_alive_client = Arc::clone(&self.http_client);\n            let keep_alive_stream = Arc::clone(self.stream_client.as_ref().unwrap());\n            let keep_alive_race_stream = self.race_stream_client.as_ref().map(Arc::clone);","sourceCodeStart":950,"sourceCodeEnd":986,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/data.rs#L950-L986","documentation":"Registering the cricket stream's fatal-error monitoring task failed; the underlying error `{e}` is re-wrapped. This watcher task detects fatal cricket-stream conditions and triggers reconnection/shutdown; connect aborts when it cannot be registered.","triggerScenarios":"connect() -> after spawning the cricket stream task, the registration's map_err wraps a spawn/registration failure. Usually because the TaskGroup or shutdown registry is closed/not open due to a concurrent shutdown, or the group generation ended before registration completed.","commonSituations":"Connect racing disconnect; reconnect loop registering tasks into an already-advancing generation; internal spawn failure in the task group.","solutions":["Inspect the inner `{e}` for the registration failure cause","Avoid overlapping connect and disconnect calls on the same client","Retry connect so the cricket stream and fatal watcher register within the same task-group generation","If the cricket stream endpoint itself failed (logged as a warning), the fatal task registration should not be attempted — verify ordering"],"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 cricket fatal task\") => {\n        log::error!(\"cricket fatal watcher not registered: {e:#}\");\n        // retry connect; ensure disconnect() isn't running concurrently\n    }\n    other => other,\n}","preventionTips":["Avoid concurrent connect/disconnect on the same client","Finish prior teardowns before reconnecting","Retry connect to register the watcher within a single task-group generation","Monitor cricket-stream connect warnings independently of registration errors"],"tags":["task-group","cricket-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"}