shadowsocks/shadowsocks-rust · error
`server_port` shouldn't be 0
Error message
`server_port` shouldn't be 0
What it means
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.
Source
Thrown at crates/shadowsocks-service/src/config.rs:2924
return Err(err);
}
for inst in &self.server {
let server = &inst.config;
// Plugin shouldn't be an empty string
if let Some(plugin) = server.plugin()
&& plugin.plugin.trim().is_empty()
{
let err = Error::new(ErrorKind::Malformed, "`plugin` shouldn't be an empty string", None);
return Err(err);
}
// Server's domain name shouldn't be an empty string
match server.addr() {
ServerAddr::SocketAddr(sa) => {
if sa.port() == 0 {
let err = Error::new(ErrorKind::Malformed, "`server_port` shouldn't be 0", None);
return Err(err);
}
if self.config_type.is_local() {
// Only server could bind to INADDR_ANY
let ip = sa.ip();
if ip.is_unspecified() {
let err = Error::new(
ErrorKind::Malformed,
"`server` shouldn't be an unspecified address (INADDR_ANY)",
None,
);
return Err(err);
}
}
#[cfg(feature = "local-online-config")]
if self.config_type.is_online_config() {View on GitHub (pinned to 8eb0f0a65b)
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.
Example fix
// before
{ "server": "1.2.3.4", "server_port": 0, "password": "pw", "method": "aes-256-gcm" }
// after
{ "server": "1.2.3.4", "server_port": 8388, "password": "pw", "method": "aes-256-gcm" } Defensive patterns
Strategy: validation
Validate before calling
// Rust let port: u16 = server_port; assert!((1..=65535).contains(&port), "server_port must be 1-65535");
Type guard
fn valid_port(p: u16) -> bool { p != 0 } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- `local_port` cannot be 0
- `local_udp_port` cannot be 0
- `server` shouldn't be an empty string, `server_port` shouldn
- missing `local_port`
- `protocol` invalid
AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09).
Data as JSON: /api/errors/211722b1217fd8eb.
Report an issue: GitHub.