{"record":{"id":"f4140a6bbedfe65a","repo":"shadowsocks/shadowsocks-rust","slug":"invalid-udp-weight-must-be-in-0-1","errorCode":null,"errorMessage":"invalid `udp_weight`, must be in [0, 1]","messagePattern":"invalid `udp_weight`, must be in \\[0, 1\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/config.rs","lineNumber":2386,"sourceCode":"                }\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,\n                        Err(err) => {\n                            let err = Error::new(\n                                ErrorKind::Invalid,\n                                \"acl loading failed\",\n                                Some(format!(\"file {acl_path}, error: {err}\")),","sourceCodeStart":2368,"sourceCodeEnd":2404,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/config.rs#L2368-L2404","documentation":"Thrown when a server entry specifies `udp_weight` outside [0.0, 1.0]. Like tcp_weight, this feeds ServerWeight for traffic balancing; the parser validates it immediately after tcp_weight and rejects values below 0 or above 1 with ErrorKind::Invalid. Defaults to 1.0 when omitted.","triggerScenarios":"Setting `\"udp_weight\": 2.0`, `\"udp_weight\": -1`, etc. in a server entry while weight fields are present (the check runs whenever either tcp_weight or udp_weight is set).","commonSituations":"Percentage-scale confusion (using 0-100 numbers); typo'd decimals; assuming UDP weight is validated only when udp_weight itself is present.","solutions":["Set udp_weight within [0.0, 1.0], e.g. 0.5 for half weight","Use 0.0 to disable UDP traffic for that server","Remove the field to accept the default of 1.0"],"exampleFix":"// before\n{\"server\": \"1.2.3.4\", \"server_port\": 8388, \"method\": \"aes-256-gcm\", \"password\": \"pw\", \"udp_weight\": 80}\n// after\n{\"server\": \"1.2.3.4\", \"server_port\": 8388, \"method\": \"aes-256-gcm\", \"password\": \"pw\", \"udp_weight\": 0.8}","handlingStrategy":"validation","validationCode":"if let Some(w) = svr.get(\"udp_weight\").and_then(|w| w.as_f64()) {\n    assert!((0.0..=1.0).contains(&w), \"udp_weight {w} out of [0,1]\");\n}","typeGuard":"fn valid_udp_weight(w: f64) -> bool { (0.0..=1.0).contains(&w) }","tryCatchPattern":"let udp_weight = svr.udp_weight.unwrap_or(1.0);\nif !(0.0..=1.0).contains(&udp_weight) {\n    eprintln!(\"clamping udp_weight {udp_weight} to [0,1]\");\n}","preventionTips":["Validate tcp_weight and udp_weight together — either being present triggers both checks","Use a shared helper to normalize weights before generating configs","Default to omitting weights unless load-balancing is intentional"],"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-14T16:17:12.679Z"}