{"record":{"id":"8a06c4020ce87d92","repo":"XTLS/Xray-core","slug":"invalid-port-range","errorCode":null,"errorMessage":"invalid port range: ","messagePattern":"invalid port range: ","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"info","filePath":"infra/conf/common.go","lineNumber":138,"sourceCode":"}\n\nfunc parseIntPort(data []byte) (net.Port, error) {\n\tvar intPort uint32\n\terr := json.Unmarshal(data, &intPort)\n\tif err != nil {\n\t\treturn net.Port(0), err\n\t}\n\treturn net.PortFromInt(intPort)\n}\n\nfunc parseStringPort(s string) (net.Port, net.Port, error) {\n\tif strings.HasPrefix(s, \"env:\") {\n\t\ts = platform.NewEnvFlag(s[4:]).GetValue(func() string { return \"\" })\n\t}\n\n\tpair := strings.SplitN(s, \"-\", 2)\n\tif len(pair) == 0 {\n\t\treturn net.Port(0), net.Port(0), errors.New(\"invalid port range: \", s)\n\t}\n\tif len(pair) == 1 {\n\t\tport, err := net.PortFromString(pair[0])\n\t\treturn port, port, err\n\t}\n\n\tfromPort, err := net.PortFromString(pair[0])\n\tif err != nil {\n\t\treturn net.Port(0), net.Port(0), err\n\t}\n\ttoPort, err := net.PortFromString(pair[1])\n\tif err != nil {\n\t\treturn net.Port(0), net.Port(0), err\n\t}\n\treturn fromPort, toPort, nil\n}\n\nfunc parseJSONStringPort(data []byte) (net.Port, net.Port, error) {","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/infra/conf/common.go#L120-L156","documentation":"Returned by parseStringPort in infra/conf/common.go when strings.SplitN(s, \"-\", 2) yields an empty slice. Because strings.SplitN always returns at least one element, this branch is effectively defensive/unreachable; in practice the companion errors from net.PortFromString (invalid number, out-of-range port) are what you hit for bad port strings. The condition exists to guard future refactors of the splitting logic.","triggerScenarios":"Cannot be triggered through normal input since SplitN never returns a zero-length slice for any string, including the empty string. The reachable failures for 'env:'-resolved or 'a-b' port strings surface as PortFromString errors instead.","commonSituations":"Developers grepping for this message after seeing port errors usually actually hit net.PortFromString errors (e.g. port 70000 or 'abc'); this specific message appearing in logs would indicate a modified/forked split helper.","solutions":["If you see a port parse error, check the actual port values: they must be integers 1-65535","For range strings use 'from-to' with from <= to, e.g. \"1000-2000\"","For env form \"env:PORT_VAR\", verify the variable resolves to a valid port or range"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember this branch is unreachable with stock Xray; treat port errors as PortFromString failures","Keep ports within 1-65535 and ranges ordered low-high"],"tags":["config","port","dead-code","validation","xray"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}