{"record":{"id":"2726cf354e9878d5","repo":"nautechsystems/nautilus_trader","slug":"no-session-token-for-race-stream","errorCode":null,"errorMessage":"No session token for race stream","messagePattern":"No session token for race stream","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/betfair/src/data.rs","lineNumber":828,"sourceCode":"        self.stream_client = Some(stream_client);\n        self.stream_shutdowns\n            .lock()\n            .push(BetfairStreamShutdown::Exchange(Arc::clone(\n                self.stream_client.as_ref().expect(\"stream client assigned\"),\n            )));\n\n        let session_result = async {\n            if self.config.subscribe_race_data {\n                let race_config = BetfairStreamConfig {\n                    host: BETFAIR_RACE_STREAM_HOST.to_string(),\n                    ..self.stream_config.clone()\n                };\n\n                let race_session = self\n                    .http_client\n                    .session_token()\n                    .await\n                    .ok_or_else(|| anyhow::anyhow!(\"No session token for race stream\"))?;\n\n                let race_handler = Self::create_stream_handler(\n                    self.data_sender.clone(),\n                    Arc::clone(&self.instruments),\n                    self.currency,\n                    self.provider.min_notional(),\n                    reconnect_tx.clone(),\n                    self.clock,\n                );\n\n                let (race_fatal_tx, mut race_fatal_rx) = tokio::sync::mpsc::unbounded_channel();\n\n                let state_sink = self\n                    .race_socket_control\n                    .as_ref()\n                    .map(|control| control.sink());\n\n                match BetfairRaceStreamClient::connect_decoded(","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/betfair/src/data.rs#L810-L846","documentation":"When setting up the optional Betfair race stream, the client needs the current session token again to authenticate that stream. session_token() returned None at that point, so this error is raised. It means the race stream cannot be opened without valid stream authentication.","triggerScenarios":"connect() -> inside the race-stream setup branch, self.http_client.session_token().await returns None even though the main connect flow previously required a token; ok_or_else raises this error. Implies the token was cleared/expired or never stored between main stream setup and race stream setup.","commonSituations":"Session expired mid-connect (long-running instrument load before race stream setup); concurrent disconnect clearing the token; Betfair login returned a token for the main stream but state got reset; enabling race stream config without stable session handling.","solutions":["Verify the main login session token exists before enabling the race stream (check http_client.session_token() prior to connect completing)","Shorten the time between login and stream setup (reduce provider.load_all latency) to avoid session expiry mid-connect","Ensure no concurrent disconnect/token-clear runs during connect","Re-authenticate (retry connect) if the session expired"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// only enable race stream when a session token is present\nif enable_race_stream && client.session_token().await.is_none() {\n    // re-authenticate before attempting connect with race stream enabled\n}","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"No session token for race stream\") => {\n        log::warn!(\"race stream auth token missing; re-authenticating\");\n        tokio::time::sleep(Duration::from_secs(1)).await;\n        client.connect().await\n    }\n    other => other,\n}","preventionTips":["Minimize work between login and stream setup to keep the session fresh","Handle session expiry with re-authentication logic","Avoid concurrent operations that clear the token during connect","Re-check session validity before enabling optional streams"],"tags":["authentication","session-token","race-stream","betfair"],"backgroundTag":"missing-credentials","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}