nautechsystems/nautilus_trader · error

Failed to finish Coinbase poll tasks: {e}

Error message

Failed to finish Coinbase poll tasks: {e}

What it means

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.

Source

Thrown at crates/adapters/coinbase/src/data/poll.rs:141

        {
            let mut polls = self.polls.lock();
            for entry in polls.values_mut() {
                entry.cancel.cancel();
                // Replace the now-cancelled token so a later `resume()` can
                // spawn a fresh task that listens on a live token.
                entry.cancel = CancellationToken::new();
            }
        }

        self.tasks.begin_shutdown();
    }

    pub(crate) async fn prepare(&self) -> anyhow::Result<()> {
        if !self.tasks.is_open() {
            self.tasks
                .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))
                .await
                .map_err(|e| anyhow::anyhow!("Failed to finish Coinbase poll tasks: {e}"))?;
            self.tasks
                .start_generation()
                .map_err(|e| anyhow::anyhow!("Failed to start Coinbase poll generation: {e}"))?;
        }
        Ok(())
    }

    pub(crate) async fn finish_shutdown(&self) -> anyhow::Result<()> {
        self.tasks
            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))
            .await
            .map_err(|e| anyhow::anyhow!("Failed to finish Coinbase poll tasks: {e}"))?;
        Ok(())
    }

    /// Spawns polling tasks for every entry with at least one active flag.
    /// Called from `connect()` so subscriptions made before a
    /// `disconnect()` remain live after the client reconnects: the data

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Wait a moment and retry connect so lingering tasks finish
  2. Check logs for a panicking poll task and fix its root cause
  3. Increase network responsiveness / check connectivity to Coinbase REST endpoints
  4. Increase the shutdown timeout in finish_shutdown if hangs are expected
  5. Fully drop and recreate the client instead of reconnecting

Example fix

// before
client.disconnect();
client.connect().await?; // immediate reconnect may race shutdown
// after
client.disconnect();
tokio::time::sleep(Duration::from_secs(3)).await;
client.connect().await?;
Defensive patterns

Strategy: try-catch

Try / catch

match client.prepare().await {
    Err(e) if e.to_string().contains("Failed to finish Coinbase poll tasks") => {
        tokio::time::sleep(Duration::from_secs(2)).await;
        client.prepare().await?; // one bounded retry
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: Rapid disconnect/reconnect cycles; a hung polling task stuck on an unresponsive network call; tokio runtime under heavy load preventing graceful completion.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/982083944fd79533. Report an issue: GitHub.