{"record":{"id":"22e8ddbad0556382","repo":"shadowsocks/shadowsocks-rust","slug":"invalid-tcp-weight-must-be-in-0-1","errorCode":null,"errorMessage":"invalid `tcp_weight`, must be in [0, 1]","messagePattern":"invalid `tcp_weight`, must be in \\[0, 1\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/config.rs","lineNumber":2381,"sourceCode":"                    }\n                }\n\n                if let Some(timeout) = config.timeout.map(Duration::from_secs) {\n                    nsvr.set_timeout(timeout);\n                }\n\n                if let Some(remarks) = svr.remarks {\n                    nsvr.set_remarks(remarks);\n                }\n\n                if let Some(id) = svr.id {\n                    nsvr.set_id(id);\n                }\n\n                if svr.tcp_weight.is_some() || svr.udp_weight.is_some() {\n                    let tcp_weight = svr.tcp_weight.unwrap_or(1.0);\n                    if !(0.0..=1.0).contains(&tcp_weight) {\n                        let err = Error::new(ErrorKind::Invalid, \"invalid `tcp_weight`, must be in [0, 1]\", None);\n                        return Err(err);\n                    }\n                    let udp_weight = svr.udp_weight.unwrap_or(1.0);\n                    if !(0.0..=1.0).contains(&udp_weight) {\n                        let err = Error::new(ErrorKind::Invalid, \"invalid `udp_weight`, must be in [0, 1]\", None);\n                        return Err(err);\n                    }\n                    let mut weight = ServerWeight::new();\n                    weight.set_tcp_weight(tcp_weight);\n                    weight.set_udp_weight(udp_weight);\n                    nsvr.set_weight(weight);\n                }\n\n                let mut server_instance = ServerInstanceConfig::with_server_config(nsvr);\n\n                if let Some(acl_path) = svr.acl {\n                    let acl = match AccessControl::load_from_file(&acl_path) {\n                        Ok(acl) => acl,","sourceCodeStart":2363,"sourceCodeEnd":2399,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/config.rs#L2363-L2399","documentation":"Thrown when a server entry specifies `tcp_weight` outside the closed interval [0.0, 1.0]. Weights are used by the manager/balancer to distribute traffic across servers; the library validates the range at config parse time and rejects out-of-range values with ErrorKind::Invalid. This check only runs when `tcp_weight` or `udp_weight` is present.","triggerScenarios":"Setting `\"tcp_weight\": 1.5`, `\"tcp_weight\": -0.2`, or any value >1 or <0 in a server entry while `tcp_weight`/`udp_weight` fields are used.","commonSituations":"Confusing percentage-style weights (0-100) with the normalized 0-1 scale; negative values intended as 'disable' (use 0.0 instead); copy-pasting weights from other load balancers with different ranges.","solutions":["Clamp the value into [0.0, 1.0] (e.g. 150 -> 1.0, 30 -> 0.3)","Use 0.0 to give a server no TCP traffic rather than a negative number","Remove `tcp_weight` to use the default weight of 1.0"],"exampleFix":"// before\n{\"server\": \"1.2.3.4\", \"server_port\": 8388, \"method\": \"aes-256-gcm\", \"password\": \"pw\", \"tcp_weight\": 150}\n// after\n{\"server\": \"1.2.3.4\", \"server_port\": 8388, \"method\": \"aes-256-gcm\", \"password\": \"pw\", \"tcp_weight\": 1.0}","handlingStrategy":"validation","validationCode":"if let Some(w) = svr.get(\"tcp_weight\").and_then(|w| w.as_f64()) {\n    assert!((0.0..=1.0).contains(&w), \"tcp_weight {w} out of [0,1]\");\n}","typeGuard":"fn valid_tcp_weight(w: f64) -> bool { (0.0..=1.0).contains(&w) }","tryCatchPattern":"let tcp_weight = svr.tcp_weight.unwrap_or(1.0);\nif !(0.0..=1.0).contains(&tcp_weight) {\n    eprintln!(\"clamping tcp_weight {tcp_weight} to [0,1]\");\n}","preventionTips":["Normalize 0-100 percentage inputs by dividing by 100 before writing configs","Use 0.0 for 'no traffic', never negatives","Keep weights in [0,1] across all server entries for consistent balancing"],"tags":["config","shadowsocks","weight","range"],"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-14T11:17:12.474Z"}