{"record":{"id":"312ee55f8c78361f","repo":"sgl-project/sglang","slug":"port-out-of-range-0-65535-port","errorCode":null,"errorMessage":"Port out of range (0-65535): {port}","messagePattern":"Port out of range \\(0-65535\\): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":447,"sourceCode":"    try:\n        ipaddress.IPv6Address(host)\n        return True\n    except ValueError:\n        return False\n\n\ndef _wrap(host: str) -> str:\n    \"\"\"Wrap an IPv6 address in brackets; pass IPv4/hostname through.\"\"\"\n    return f\"[{host}]\" if _is_ipv6(host) else host\n\n\ndef _parse_port(s: str) -> int:\n    try:\n        port = int(s)\n    except ValueError:\n        raise ValueError(f\"Invalid port number: {s!r}\")\n    if not (0 <= port <= 65535):\n        raise ValueError(f\"Port out of range (0-65535): {port}\")\n    return port\n\n\n@dataclass(frozen=True)\nclass NetworkAddress:\n    host: str\n    port: int\n\n    def __post_init__(self):\n        # Auto-strip IPv6 brackets so callers can pass \"[::1]\" or \"::1\"\n        if self.host.startswith(\"[\") and self.host.endswith(\"]\"):\n            object.__setattr__(self, \"host\", self.host[1:-1])\n\n    @property\n    def is_ipv6(self) -> bool:\n        return _is_ipv6(self.host)\n\n    @property","sourceCodeStart":429,"sourceCodeEnd":465,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L429-L465","documentation":"The second stage of _parse_port: the substring parsed to an int successfully but the value is negative or above 65535, which is not a valid TCP port. Raised with the numeric value for easy spotting of off-by-1000 or hex/decimal mistakes.","triggerScenarios":"NetworkAddress.parse(\"host:70000\") or a port computed from config arithmetic exceeding 65535, or a negative value from subtraction.","commonSituations":"Port offsets added across many data-parallel workers; hex strings parsed as decimal; 0 used as base then decremented.","solutions":["Correct the port number to 0-65535.","Validate generated port plans before constructing addresses.","Allocate ports with get_open_port() rather than computing them."],"exampleFix":"# before\nNetworkAddress.parse(\"10.0.0.1:70000\")\n\n# after\nNetworkAddress.parse(\"10.0.0.1:8000\")","handlingStrategy":"validation","validationCode":"port = int(port_str)\nassert 0 <= port <= 65535, f\"port {port} out of range\"","typeGuard":"def is_tcp_port(v) -> bool:\n    return isinstance(v, int) and 0 <= v <= 65535","tryCatchPattern":null,"preventionTips":["Bound-check computed port plans (base + rank*stride) at config time."],"tags":["network","port","parsing"],"backgroundTag":"port-out-of-range","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}