{"record":{"id":"a35e3200669df575","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-betfair-reconnect-task-e","errorCode":null,"errorMessage":"Failed to register Betfair reconnect task: {e}","messagePattern":"Failed to register Betfair reconnect task: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/data.rs","lineNumber":1079,"sourceCode":"                                continue;\n                            }\n                        };\n\n                        let _ = reconnect_http\n                            .with_session_token(|token| {\n                                refresh_stream_sessions(\n                                    reconnect_stream.as_ref(),\n                                    reconnect_race_stream.as_deref(),\n                                    reconnect_cricket_stream.as_deref(),\n                                    &reconnect_app_key,\n                                    token,\n                                    session_replaced,\n                                );\n                            })\n                            .await;\n                    }\n                })\n                .map_err(|e| anyhow::anyhow!(\"Failed to register Betfair reconnect task: {e}\"))?;\n\n            Ok::<(), anyhow::Error>(())\n        }\n        .await;\n\n        if let Err(e) = session_result {\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(e.context(format!(\n                    \"Betfair data startup teardown failed: {teardown_error}\"\n                )));\n            }\n            return Err(e);\n        }\n\n        self.is_connected.store(true, Ordering::Release);\n        setup_guard.disarm();\n\n        log::info!(\"Betfair data client connected: {}\", self.client_id);","sourceCodeStart":1061,"sourceCodeEnd":1097,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/data.rs#L1061-L1097","documentation":"At the end of connect, the Betfair data client spawns a reconnect task that re-establishes the streaming connection on drop. If registering this reconnect task fails, connect wraps the inner error with this message and returns Err, aborting the connection setup.","triggerScenarios":"The reconnect-task registration future returns Err — typically runtime shutdown in progress, a closed registration channel, or connecting after teardown_partial_connect has begun.","commonSituations":"Connecting while the actor system is stopping; calling connect from a dying task; a previous failed connect left the client partially torn down.","solutions":["Retry connect after teardown completes, not while it is in progress","Verify the tokio runtime is active for the lifetime of the adapter","Check the inner error `e` to identify the exact registration failure"],"exampleFix":"// before: connect racing teardown\nlet _ = tokio::spawn(async { client.disconnect().await });\nclient.connect().await?;\n// after: sequential lifecycle\ntokio::spawn(async { client.disconnect().await }).await.ok();\nclient.connect().await?;","handlingStrategy":"retry","validationCode":"// ensure prior disconnect finished\nlet _ = client.disconnect().await;","typeGuard":null,"tryCatchPattern":"if let Err(e) = market_client.connect().await {\n    if e.to_string().contains(\"reconnect task\") {\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        market_client.connect().await?;\n    } else { return Err(e); }\n}","preventionTips":["Await disconnect completion before reconnecting","Keep the tokio runtime alive as long as the adapter exists","Avoid aborting lifecycle futures"],"tags":["rust","tokio","betfair","task-spawn","reconnect"],"backgroundTag":"network-request-failed","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"}