{"record":{"id":"a0efdf56b1c653c6","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-polymarket-task-generation-e","errorCode":null,"errorMessage":"Failed to start Polymarket task generation: {e}","messagePattern":"Failed to start Polymarket task generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/data/lifecycle.rs","lineNumber":510,"sourceCode":"    }\n\n    pub(super) async fn connect_client(&mut self) -> anyhow::Result<()> {\n        if self.is_connected() && self.tasks.is_open() && !self.reset_pending {\n            return Ok(());\n        }\n\n        if self.reset_pending\n            || !self.tasks.is_empty()\n            || !self.tasks.is_open()\n            || self.ws_client.connection_count() > 0\n        {\n            self.disconnect_client().await?;\n        }\n\n        if !self.tasks.is_open() {\n            self.tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Polymarket task generation: {e}\"))?;\n            self.cancellation_token = self.tasks.cancellation_token();\n        }\n\n        let ws_client = self.ws_client.handle();\n        let rtds_feed = self.rtds_feed.clone();\n        let setup_guard = TaskGroupGuard::new(&[&self.tasks], move || {\n            ws_client.begin_shutdown();\n            rtds_feed.begin_shutdown();\n        });\n        self.ensure_position_event_subscription();\n        register_polymarket_custom_data();\n\n        log::info!(\"Connecting Polymarket data client\");\n\n        log::debug!(\"Bootstrapping instruments from Gamma API...\");\n        self.bootstrap_instruments().await?;\n        log::debug!(\n            \"Bootstrap complete, {} instruments loaded\",","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/data/lifecycle.rs#L492-L528","documentation":"connect_client calls tasks.start_generation() when the task group is not open. If that call fails (task group cannot begin a new admission generation, e.g. it is in a bad shutdown state or the underlying runtime facility is unavailable), this error propagates out of connect().","triggerScenarios":"Calling connect()/connect on a client whose task group fails start_generation() — group wedged mid-shutdown, or spawner infrastructure reporting closure.","commonSituations":"Reconnecting a client immediately after a failed/aborted disconnect; disconnect that timed out (see 'Failed to terminate Polymarket data tasks') leaving the group in a partial shutdown state; process teardown in progress.","solutions":["Wait for the previous disconnect to fully complete (including task termination) before reconnecting","Construct a fresh client instance if the previous generation failed to close cleanly","Increase disconnect timeout to avoid leaving the group half-shut-down","Ensure the tokio runtime is healthy and not being torn down"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"let client = match client.connect().await {\n    Err(e) if e.to_string().contains(\"task generation\") => {\n        warn!(\"generation start failed; rebuilding client\");\n        let mut c = build_client(cfg)?;\n        c.connect().await?;\n        c\n    }\n    _ => client,\n};","preventionTips":["Let a timed-out disconnect fully drain before reconnecting (wait grace period)","Increase disconnect timeouts to avoid half-shutdown groups","Rebuild the client instance when start_generation repeatedly fails"],"tags":["rust","tokio","task-group","lifecycle"],"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"}