{"record":{"id":"211722b1217fd8eb","repo":"shadowsocks/shadowsocks-rust","slug":"server-port-shouldn-t-be-0","errorCode":null,"errorMessage":"`server_port` shouldn't be 0","messagePattern":"`server_port` shouldn't be 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/config.rs","lineNumber":2924,"sourceCode":"            return Err(err);\n        }\n\n        for inst in &self.server {\n            let server = &inst.config;\n\n            // Plugin shouldn't be an empty string\n            if let Some(plugin) = server.plugin()\n                && plugin.plugin.trim().is_empty()\n            {\n                let err = Error::new(ErrorKind::Malformed, \"`plugin` shouldn't be an empty string\", None);\n                return Err(err);\n            }\n\n            // Server's domain name shouldn't be an empty string\n            match server.addr() {\n                ServerAddr::SocketAddr(sa) => {\n                    if sa.port() == 0 {\n                        let err = Error::new(ErrorKind::Malformed, \"`server_port` shouldn't be 0\", None);\n                        return Err(err);\n                    }\n\n                    if self.config_type.is_local() {\n                        // Only server could bind to INADDR_ANY\n                        let ip = sa.ip();\n                        if ip.is_unspecified() {\n                            let err = Error::new(\n                                ErrorKind::Malformed,\n                                \"`server` shouldn't be an unspecified address (INADDR_ANY)\",\n                                None,\n                            );\n                            return Err(err);\n                        }\n                    }\n\n                    #[cfg(feature = \"local-online-config\")]\n                    if self.config_type.is_online_config() {","sourceCodeStart":2906,"sourceCodeEnd":2942,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/config.rs#L2906-L2942","documentation":"When a server address is given as a socket address, its port must be non-zero. Port 0 is not a valid shadowsocks server port, so Config::check rejects it with ErrorKind::Malformed while iterating over all configured servers.","triggerScenarios":"A server entry whose address is an IP:port socket address with port 0 — e.g. server_port = 0 in JSON/TOML, an ss:// URL like ss://...@host:0, or a SIP008 entry with port 0.","commonSituations":"Placeholder configs not yet filled in (server_port left at 0); subscription/registration data with a missing port defaulting to 0; template configs where the port variable was empty.","solutions":["Set server_port to a valid port (1-65535), typically 8388 or your provider's assigned port.","Fix the ss:// URL or SIP008 payload so the port is specified.","Add a pre-flight check in your tooling that asserts port > 0 before writing the config."],"exampleFix":"// before\n{ \"server\": \"1.2.3.4\", \"server_port\": 0, \"password\": \"pw\", \"method\": \"aes-256-gcm\" }\n\n// after\n{ \"server\": \"1.2.3.4\", \"server_port\": 8388, \"password\": \"pw\", \"method\": \"aes-256-gcm\" }","handlingStrategy":"validation","validationCode":"// Rust\nlet port: u16 = server_port;\nassert!((1..=65535).contains(&port), \"server_port must be 1-65535\");","typeGuard":"fn valid_port(p: u16) -> bool { p != 0 }","tryCatchPattern":null,"preventionTips":["Never leave server_port at a 0 placeholder in templates.","Validate subscription payloads (port != 0) before writing configs.","Prefer named constants (e.g. 8388) over unset variables in generated configs."],"tags":["config","port","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}