{"record":{"id":"982083944fd79533","repo":"nautechsystems/nautilus_trader","slug":"failed-to-finish-coinbase-poll-tasks-e","errorCode":null,"errorMessage":"Failed to finish Coinbase poll tasks: {e}","messagePattern":"Failed to finish Coinbase poll tasks: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/coinbase/src/data/poll.rs","lineNumber":141,"sourceCode":"        {\n            let mut polls = self.polls.lock();\n            for entry in polls.values_mut() {\n                entry.cancel.cancel();\n                // Replace the now-cancelled token so a later `resume()` can\n                // spawn a fresh task that listens on a live token.\n                entry.cancel = CancellationToken::new();\n            }\n        }\n\n        self.tasks.begin_shutdown();\n    }\n\n    pub(crate) async fn prepare(&self) -> anyhow::Result<()> {\n        if !self.tasks.is_open() {\n            self.tasks\n                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n                .await\n                .map_err(|e| anyhow::anyhow!(\"Failed to finish Coinbase poll tasks: {e}\"))?;\n            self.tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Coinbase poll generation: {e}\"))?;\n        }\n        Ok(())\n    }\n\n    pub(crate) async fn finish_shutdown(&self) -> anyhow::Result<()> {\n        self.tasks\n            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to finish Coinbase poll tasks: {e}\"))?;\n        Ok(())\n    }\n\n    /// Spawns polling tasks for every entry with at least one active flag.\n    /// Called from `connect()` so subscriptions made before a\n    /// `disconnect()` remain live after the client reconnects: the data","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/coinbase/src/data/poll.rs#L123-L159","documentation":"During `prepare`, if the poll task set is not open, the adapter first finishes any prior shutdown of the Coinbase poll tasks. If `finish_shutdown` (awaiting task termination within 1s drain / 2s timeout) fails, this error is raised.","triggerScenarios":"Calling connect/prepare while poll tasks from a previous generation are still shutting down and a task hangs or panics past the 2-second timeout.","commonSituations":"Rapid disconnect/reconnect cycles; a hung polling task stuck on an unresponsive network call; tokio runtime under heavy load preventing graceful completion.","solutions":["Wait a moment and retry connect so lingering tasks finish","Check logs for a panicking poll task and fix its root cause","Increase network responsiveness / check connectivity to Coinbase REST endpoints","Increase the shutdown timeout in finish_shutdown if hangs are expected","Fully drop and recreate the client instead of reconnecting"],"exampleFix":"// before\nclient.disconnect();\nclient.connect().await?; // immediate reconnect may race shutdown\n// after\nclient.disconnect();\ntokio::time::sleep(Duration::from_secs(3)).await;\nclient.connect().await?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.prepare().await {\n    Err(e) if e.to_string().contains(\"Failed to finish Coinbase poll tasks\") => {\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        client.prepare().await?; // one bounded retry\n    }\n    other => other?,\n}","preventionTips":["Avoid hot disconnect/reconnect loops; add a cooldown","Monitor Coinbase REST latency to spot hangs early","Fix panicking poll handlers promptly — they block teardown"],"tags":["rust","async","shutdown","tasks","coinbase"],"backgroundTag":"request-timeout","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"}