{"record":{"id":"1f6d91c77f389792","repo":"nautechsystems/nautilus_trader","slug":"reconnection-timed-out-after-s","errorCode":null,"errorMessage":"reconnection timed out after {}s","messagePattern":"reconnection timed out after (.+?)s","errorType":"exception","errorClass":"Error::Io(std::io::Error)","httpStatus":null,"severity":"error","filePath":"crates/network/src/socket/client.rs","lineNumber":389,"sourceCode":"        log::info!(\"Reconnecting\");\n\n        if ConnectionMode::from_atomic(&self.connection_mode).is_disconnect() {\n            log::debug!(\"Reconnect aborted due to disconnect state\");\n            return Ok(ReconnectOutcome::Aborted);\n        }\n\n        // Bound only connection establishment; the swap below must run to completion\n        let (reader, new_writer) = dst::time::timeout(\n            self.connect_timeout,\n            Self::tls_connect_with_server(\n                &self.config.url,\n                self.config.mode,\n                self.connector.clone(),\n            ),\n        )\n        .await\n        .map_err(|_| {\n            Error::Io(std::io::Error::new(\n                std::io::ErrorKind::TimedOut,\n                format!(\n                    \"reconnection timed out after {}s\",\n                    self.connect_timeout.as_secs_f64()\n                ),\n            ))\n        })??;\n\n        if ConnectionMode::from_atomic(&self.connection_mode).is_disconnect() {\n            log::debug!(\"Reconnect aborted mid-flight (after connect)\");\n            return Ok(ReconnectOutcome::Aborted);\n        }\n        log::debug!(\"Connected\");\n\n        // Use a oneshot channel to synchronize with the writer task.\n        // We must verify that the buffer was successfully drained before transitioning to ACTIVE\n        // to prevent silent message loss if the new connection drops immediately.\n        let (tx, rx) = tokio::sync::oneshot::channel();","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/network/src/socket/client.rs#L371-L407","documentation":"The library spawns a reconnection future (using the configured connector and mode) inside a timeout, and the future did not complete within `connect_timeout` seconds. The result is a `ErrorKind::TimedOut` Io error, meaning the remote endpoint did not accept the new connection in time.","triggerScenarios":"Calling reconnect logic (automatically on connection loss or via explicit reconnect) while the remote server is down, unreachable, dropping SYN packets, or when `connect_timeout` is set too aggressively for a slow network.","commonSituations":"Exchange/data-feed endpoints behind firewalls that silently drop traffic, DNS or routing problems, server restarts longer than the configured timeout, or misconfigured timeouts of a few hundred milliseconds.","solutions":["Verify the remote host:port is reachable (`ping`, `nc -vz host port`) and the server is up.","Increase `connect_timeout` in the client config to a realistic value (e.g. 10–30s).","Check for firewall/VPN/proxy rules blocking outbound connections to the endpoint.","Retry reconnection with backoff; transient outages often resolve."],"exampleFix":"// before\nconfig.connect_timeout = Duration::from_millis(500);\n// after\nconfig.connect_timeout = Duration::from_secs(15);","handlingStrategy":"retry","validationCode":"// pre-check endpoint reachability before reconnecting\nassert!(std::net::TcpStream::connect_timeout(\n    &addr, Duration::from_secs(3)).is_ok(), \"endpoint unreachable\");","typeGuard":null,"tryCatchPattern":"match client.reconnect().await {\n    Err(e) if e.kind() == std::io::ErrorKind::TimedOut => {\n        tokio::time::sleep(backoff.next()).await;\n        // retry reconnect\n    }\n    Err(e) => return Err(e),\n    Ok(()) => {}\n}","preventionTips":["Set connect_timeout to a realistic multiple of worst-case RTT.","Monitor endpoint health before attempting reconnects.","Use exponential backoff with jitter between reconnect attempts.","Verify firewalls/VPN allow the endpoint's host and port."],"tags":["network","timeout","reconnect","rust"],"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"}