{"record":{"id":"4ff70e44e9201962","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-hyperliquid-data-session-generatio","errorCode":null,"errorMessage":"Failed to start Hyperliquid data session generation: {e}","messagePattern":"Failed to start Hyperliquid data session generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/data.rs","lineNumber":640,"sourceCode":"        {\n            // `reset()` is synchronous, while shutting down the inner socket\n            // is async. Complete that teardown before creating any new stream\n            // task so its receiver and subscription registries cannot belong\n            // to the previous generation.\n            self.ws_client.begin_shutdown();\n            self.ws_client\n                .disconnect()\n                .await\n                .context(\"failed to tear down Hyperliquid WebSocket before reconnect\")?;\n            self.ws_client.reset_runtime_state();\n            self.abort_session_tasks();\n            self.abort_pending_tasks();\n            let (session_result, pending_result) =\n                tokio::join!(self.await_session_tasks(), self.await_pending_tasks());\n            session_result?;\n            pending_result?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Hyperliquid data session generation: {e}\")\n            })?;\n            self.pending_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Hyperliquid data task generation: {e}\")\n            })?;\n            self.cancellation_token = CancellationToken::new();\n        }\n        let cancellation_token = self.cancellation_token.clone();\n        let ws_client = self.ws_client.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                cancellation_token.cancel();\n                ws_client.begin_shutdown();\n            });\n\n        register_hyperliquid_custom_data();\n\n        let instruments = self\n            .bootstrap_instruments()","sourceCodeStart":622,"sourceCodeEnd":658,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/data.rs#L622-L658","documentation":"Raised in `connect` when, after aborting pending work and awaiting old session/pending tasks, `session_tasks.start_generation()` fails. The task manager refuses to begin a new generation of WebSocket session tasks (e.g. it is not in a state where a new generation can start, or prior generation bookkeeping is inconsistent). Connection cannot proceed, so the connect attempt fails with this message.","triggerScenarios":"Calling connect on the Hyperliquid data client when the internal session task manager rejects `start_generation` — typically after a previous shutdown did not fully reset the task registry or a concurrent connect/teardown raced.","commonSituations":"Rapid connect/disconnect cycles; concurrent connect calls from multiple threads/tasks on the same client; a prior error[3100]-style shutdown timeout leaving the manager in a dirty state.","solutions":["Retry connect once after the previous teardown has fully completed (await the disconnect).","Avoid calling connect concurrently; serialize connection lifecycle on one task/lock.","If persistent, recreate the data client instance to get a fresh task manager.","Report/upgrade if a clean sequence (disconnect then connect) still fails repeatedly."],"exampleFix":"// before\ntokio::join!(client.connect(), client.connect()); // racing connects\n// after\ndisconnect_handle.await; // ensure prior teardown finished\nclient.connect().await?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// ensure serialized lifecycle and treat as transient\nmatch client.connect().await {\n    Err(e) if e.to_string().contains(\"session generation\") => {\n        tokio::time::sleep(Duration::from_millis(500)).await;\n        client.connect().await?; // one retry after teardown settles\n    }\n    r => r?,\n}","preventionTips":["Never call connect concurrently on the same client; guard with a lock/single task.","Always complete disconnect (propagate its errors) before reconnecting.","Recreate the client after repeated generation-start failures instead of retrying indefinitely."],"tags":["websocket","connect","lifecycle","async","hyperliquid"],"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-14T05:17:10.506Z"}