{"record":{"id":"d5a54f839645bdfd","repo":"shadowsocks/shadowsocks-rust","slug":"connect-timeout","errorCode":null,"errorMessage":"connect {} timeout","messagePattern":"connect (.+?) timeout","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks/src/relay/tcprelay/proxy_stream/client.rs","lineNumber":124,"sourceCode":"        opts: &ConnectOpts,\n        map_fn: F,\n    ) -> io::Result<Self>\n    where\n        A: Into<Address>,\n        F: FnOnce(OutboundTcpStream) -> S,\n    {\n        let stream = match svr_cfg.timeout() {\n            Some(d) => {\n                match time::timeout(\n                    d,\n                    OutboundTcpStream::connect_server_with_opts(&context, svr_cfg.tcp_external_addr(), opts),\n                )\n                .await\n                {\n                    Ok(Ok(s)) => s,\n                    Ok(Err(e)) => return Err(e),\n                    Err(..) => {\n                        return Err(io::Error::new(\n                            ErrorKind::TimedOut,\n                            format!(\"connect {} timeout\", svr_cfg.addr()),\n                        ));\n                    }\n                }\n            }\n            None => OutboundTcpStream::connect_server_with_opts(&context, svr_cfg.tcp_external_addr(), opts).await?,\n        };\n\n        trace!(\n            \"connected tcp remote {} (outbound: {}) with {:?}\",\n            svr_cfg.addr(),\n            svr_cfg.tcp_external_addr(),\n            opts\n        );\n\n        Ok(Self::from_stream(context, map_fn(stream), svr_cfg, addr))\n    }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks/src/relay/tcprelay/proxy_stream/client.rs#L106-L142","documentation":"When establishing the TCP connection to a shadowsocks server, the connect is wrapped in a timeout (from the server's connect_timeout option). If the underlying TCP connect neither succeeds nor fails before the deadline, the library aborts with ErrorKind::TimedOut and \"connect <addr> timeout\". This is a transport-level timeout, not an authentication or protocol failure.","triggerScenarios":"connect_with_opts_map connects to svr_cfg.addr() while connect_timeout elapses: server IP unreachable (firewall drops SYN), wrong server address/port in config, network outage, or server overloaded and not accepting connections.","commonSituations":"Server blocked by GFW/firewall silently dropping packets; typo in server host/port; server process down; switching networks (WiFi→cellular) with stale routing; DNS resolving to an unreachable IP.","solutions":["Verify the server address/port are correct and the server is reachable (`ping`/`nc -vz host port`)","Increase connect_timeout in the server config if the network is slow but functional","Check local firewall/VPN rules and the network path to the server","If the server IP is blocked, change the server IP/port or use a different transport (e.g. plugin)","Retry — transient outages or network switches often resolve on a fresh attempt"],"exampleFix":"// before\nServerConfig::new(addr, password, method.clone()) // default/no timeout tuning\n// after\nlet mut sc = ServerConfig::new(addr, password, method.clone());\nsc.set_connect_timeout(Some(Duration::from_secs(10))); // allow slow links","handlingStrategy":"retry","validationCode":"// Probe server reachability before starting the client\nlet addr = svr_cfg.addr();\nmatch tokio::time::timeout(\n    Duration::from_secs(connect_timeout_secs),\n    tokio::net::TcpStream::connect(addr),\n).await {\n    Ok(Ok(_)) => { /* proceed */ }\n    _ => eprintln!(\"warning: server {} unreachable, check address/firewall\", addr),\n}","typeGuard":null,"tryCatchPattern":"match client.connect(&opts).await {\n    Err(e) if e.kind() == std::io::ErrorKind::TimedOut && e.to_string().starts_with(\"connect \") => {\n        backoff_retry(|| client.connect(&opts), 3, Duration::from_secs(2)).await\n    }\n    r => r,\n}","preventionTips":["Set a realistic connect_timeout for slow networks (>= 5s on mobile)","Monitor server availability and keep a fallback server list","Verify server IP/port after any migration; silent SYN drops look exactly like this timeout","Test reachability from the deployment network — blocked IPs fail with no other symptom"],"tags":["timeout","tcp","connect","network"],"backgroundTag":"request-timeout","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}