nautechsystems/nautilus_trader · error

Failed to terminate Coinbase execution tasks: {e}

Error message

Failed to terminate Coinbase execution tasks: {e}

What it means

`await_pending_tasks` begins shutdown of the execution client's pending-task set and awaits completion with a 1s drain and 2s timeout (called from connect during reconnect). Failure is wrapped in this error.

Source

Thrown at crates/adapters/coinbase/src/execution.rs:255

            log::warn!("Skipping Coinbase {description} after shutdown began: {e}");
        }
    }

    fn abort_pending_tasks(&self) {
        self.pending_tasks.begin_shutdown();
    }

    fn abort_session_tasks(&self) {
        self.session_tasks.begin_shutdown();
        self.ws_user.begin_shutdown();
    }

    async fn await_pending_tasks(&self) -> anyhow::Result<()> {
        self.pending_tasks.begin_shutdown();
        self.pending_tasks
            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))
            .await
            .map_err(|e| anyhow::anyhow!("Failed to terminate Coinbase execution tasks: {e}"))?;
        Ok(())
    }

    async fn await_session_tasks(&self) -> anyhow::Result<()> {
        self.session_tasks.begin_shutdown();
        self.session_tasks
            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))
            .await
            .map_err(|e| anyhow::anyhow!("Failed to terminate Coinbase session tasks: {e}"))?;
        Ok(())
    }

    async fn teardown_partial_connect(&mut self) -> anyhow::Result<()> {
        self.abort_session_tasks();
        self.abort_pending_tasks();

        if let Err(e) = self.ws_user.disconnect().await {
            self.shutdown_errors.push(e.to_string());

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Retry connect after letting prior tasks settle
  2. Check logs for the hung/panicked pending task and fix its cause
  3. Verify network connectivity to Coinbase before reconnecting
  4. Fully recreate the execution client if task state is stuck
  5. Increase the shutdown timeout in await_pending_tasks

Example fix

// before
client.disconnect().await?;
client.connect().await?; // may race pending-task teardown
// after
client.disconnect().await?;
tokio::time::sleep(Duration::from_secs(3)).await;
client.connect().await?;
Defensive patterns

Strategy: retry

Try / catch

for attempt in 0..3 {
    match client.connect().await {
        Ok(_) => break,
        Err(e) if e.to_string().contains("Failed to terminate Coinbase execution tasks") => {
            tokio::time::sleep(Duration::from_millis(1000 * (attempt + 1))).await;
        }
        Err(e) => return Err(e),
    }
}

Prevention

When it happens

Trigger: Calling connect() when a previous generation of pending execution tasks (orders in flight, pending requests) is still shutting down and a task hangs or panics past the 2s timeout.

Common situations: Rapid disconnect/reconnect cycles on the trading client; a pending order request blocked on a stalled WebSocket/HTTP connection to Coinbase.

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/26348d9a2dfa9369. Report an issue: GitHub.