nautechsystems/nautilus_trader · error

std::mem::take(&mut self.shutdown_errors).join("; ")

Error message

std::mem::take(&mut self.shutdown_errors).join("; ")

What it means

During AX data-client connect, `teardown_partial_connect` runs finish_all_tasks and other cleanup; any errors accumulated into self.shutdown_errors are drained and reported as a single joined bail. It surfaces failure to cleanly tear down a partially established connection, masking the original connect error.

Source

Thrown at crates/adapters/architect_ax/src/data.rs:383

        session_result
            .map_err(|e| anyhow::anyhow!("Failed to terminate AX data session tasks: {e}"))?;
        Ok(())
    }

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

        if let Err(e) = self.ws_client.close().await {
            self.shutdown_errors.push(e.to_string());
        }

        if let Err(e) = self.finish_all_tasks().await {
            self.shutdown_errors.push(e.to_string());
        }
        self.is_connected.store(false, Ordering::Release);

        if !self.shutdown_errors.is_empty() {
            anyhow::bail!(std::mem::take(&mut self.shutdown_errors).join("; "));
        }
        Ok(())
    }
}

#[async_trait(?Send)]
impl DataClient for AxDataClient {
    fn client_id(&self) -> ClientId {
        self.client_id
    }

    fn venue(&self) -> Option<Venue> {
        Some(*AX_VENUE)
    }

    fn start(&mut self) -> anyhow::Result<()> {
        log::debug!("Starting {}", self.client_id);
        Ok(())

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read all ';'-joined messages in the error: the first usually points at the root connect cause, later ones at teardown side effects
  2. Verify network/TLS reachability of the AX gateway and credentials, then retry connect
  3. Inspect finish_all_tasks error sources (task panics, channel closes) if teardown messages dominate
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check gateway reachability before connect
TcpStream::connect((host, port)).await.context("AX gateway unreachable")?;

Try / catch

match data_client.connect().await {
    Ok(()) => {},
    Err(e) => {
        log::error!("AX data connect failed: {e}"); // includes joined teardown errors
        backoff_retry(connect, max_attempts = 3).await?;
    }
}

Prevention

When it happens

Trigger: connect() on AXDataClient fails partway (websocket handshake error, task spawn failure) and one or more teardown steps (finish_all_tasks, closing streams) also error.

Common situations: AX gateway unreachable or TLS problems causing partial connect; shutdown racing an in-flight task; network interruption during startup.

Understand the failure class

Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.

Related errors


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