nautechsystems/nautilus_trader · error · TransportError

reconnection timed out after {}s

Error message

reconnection timed out after {}s

What it means

During reconnection, the client awaits the new connection with a future bounded by the configured connect_timeout. If the underlying connect (including backend/proxy setup) does not finish within that window, the retry is abandoned and this TimedOut TransportError is returned to the reconnect caller. It indicates the peer, DNS, proxy, or network path is too slow or unreachable for the configured budget.

Source

Thrown at crates/network/src/websocket/client.rs:1329

        if ConnectionMode::from_atomic(&self.connection_mode).is_disconnect() {
            log::debug!("Reconnect aborted during connection rate-limit wait");
            return Ok(ReconnectOutcome::Aborted);
        }

        // Bound only connection establishment; the swap below must run to completion
        let (new_writer, reader) = dst::time::timeout(
            self.connect_timeout,
            Box::pin(Self::connect_with_server(
                &self.config.url,
                self.reconnect_headers.snapshot(),
                self.config.backend,
                self.config.proxy_url.as_deref(),
            )),
        )
        .await
        .map_err(|_| {
            TransportError::Io(std::io::Error::new(
                std::io::ErrorKind::TimedOut,
                format!(
                    "reconnection timed out after {}s",
                    self.connect_timeout.as_secs_f64()
                ),
            ))
        })??;

        if ConnectionMode::from_atomic(&self.connection_mode).is_disconnect() {
            log::debug!("Reconnect aborted mid-flight (after connect)");
            return Ok(ReconnectOutcome::Aborted);
        }

        // Use a oneshot channel to synchronize the writer swap before transitioning
        // back to ACTIVE. Buffered messages stay in the writer task and replay later.
        let (tx, rx) = tokio::sync::oneshot::channel();
        if let Err(e) = self.writer_tx.send(WriterCommand::Update(new_writer, tx)) {
            log::error!("{e}");

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Increase connect_timeout in the WebSocketClient config to a realistic value for your network path
  2. Verify the WebSocket endpoint URL/DNS and any proxy_url are correct and reachable (curl/telnet the host:port)
  3. Check server-side logs for handshake stalls or overloaded accept queues
  4. Wrap reconnect in an outer retry loop with backoff so a single timeout does not kill the session permanently

Example fix

// before
WebSocketClientConfig::builder().connect_timeout(Duration::from_secs(5))
// after
WebSocketClientConfig::builder().connect_timeout(Duration::from_secs(30))
Defensive patterns

Strategy: retry

Validate before calling

// Pre-check reachability before reconnect
if std::net::TcpStream::connect_timeout(&addr, Duration::from_secs(3)).is_err() {
    // delay reconnect until network is back
}

Type guard

fn is_reconnect_timeout(e: &TransportError) -> bool {
    matches!(e, TransportError::Io(io) if io.kind() == std::io::ErrorKind::TimedOut)
}

Try / catch

match client.reconnect().await {
    Err(e) if is_reconnect_timeout(&e) => backoff.wait_and_retry(),
    Err(e) => return Err(e),
    Ok(()) => {}
}

Prevention

When it happens

Trigger: Calling reconnect (via reconnect_with_outcome) while the remote host is unreachable or slow; connect_timeout too small for slow networks or proxied backends; server accepting TCP but never completing the WebSocket handshake within the budget.

Common situations: Network outages or flaky Wi-Fi during a trading session; DNS resolution stalls; misconfigured proxy_url adding latency; backend service degraded; connect_timeout set optimistically low (e.g. 5s) for cross-region links.

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/49a1f3e7ad2d162a. Report an issue: GitHub.