{"record":{"id":"59c46bce5382e700","repo":"sgl-project/sglang","slug":"missing-port-in-address-expected-host-port-add","errorCode":null,"errorMessage":"Missing port in address (expected host:port): {addr!r}","messagePattern":"Missing port in address \\(expected host:port\\): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":545,"sourceCode":"\n        # --- Bracketed IPv6: [addr]:port ---\n        if addr.startswith(\"[\"):\n            close = addr.find(\"]\")\n            if close == -1:\n                raise ValueError(f\"Missing closing bracket in IPv6 address: {addr!r}\")\n            host = addr[1:close]\n            if not _is_ipv6(host):\n                raise ValueError(f\"Invalid IPv6 address inside brackets: {host!r}\")\n            rest = addr[close + 1 :]\n            if not rest.startswith(\":\") or len(rest) < 2:\n                raise ValueError(\n                    f\"Expected ':port' after closing bracket, got: {rest!r}\"\n                )\n            return NetworkAddress(host, _parse_port(rest[1:]))\n\n        # --- Plain host:port (IPv4 / hostname) ---\n        if \":\" not in addr:\n            raise ValueError(f\"Missing port in address (expected host:port): {addr!r}\")\n        host, port_str = addr.rsplit(\":\", 1)\n        if not host:\n            raise ValueError(f\"Empty host in address: {addr!r}\")\n        # Guard against bare IPv6 slipping through\n        if \":\" in host and _is_ipv6(host):\n            raise ValueError(\n                f\"Bare IPv6 address without brackets is ambiguous: {addr!r}. \"\n                f\"Use [{host}]:{port_str} instead.\"\n            )\n        return NetworkAddress(host, _parse_port(port_str))\n\n    def __str__(self) -> str:\n        return self.to_host_port_str()\n\n    def __repr__(self) -> str:\n        return f\"NetworkAddress({self.host!r}, {self.port})\"\n\n","sourceCodeStart":527,"sourceCodeEnd":563,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L527-L563","documentation":"NetworkAddress.parse was given a string with no ':' at all and not starting with '[', so no port can be extracted. Every address passed to parse must be in host:port (or [ipv6]:port) form.","triggerScenarios":"NetworkAddress.parse('localhost'), '10.0.0.1', or a bare IPv6 without brackets like '::1' (no brackets means the ':' check path differs, but pure hostnames hit this).","commonSituations":"Passing a hostname where a host:port pair is expected — e.g. --host without --port concatenated, or reading a host-only env var into an address field.","solutions":["Append the port: 'localhost:8080'","Fix the code that assembles the address to always join host and port","Default the port at the call site if a bare host is legitimately allowed"],"exampleFix":"# before\naddr = NetworkAddress.parse(host)  # host == 'worker-0'\n# after\naddr = NetworkAddress.parse(f'{host}:{port}')","handlingStrategy":"validation","validationCode":"def has_host_and_port(addr: str) -> bool:\n    return bool(addr) and not addr.startswith('[') and ':' in addr","typeGuard":"null","tryCatchPattern":"try:\n    NetworkAddress.parse(addr)\nexcept ValueError as e:\n    if 'Missing port' in str(e):\n        addr = f'{addr}:{DEFAULT_PORT}'","preventionTips":["Never pass a bare hostname to NetworkAddress.parse","Centralize host+port joining in config code","Assert ':' in addr in debug builds"],"tags":["network","port","address-parsing","sglang"],"backgroundTag":"invalid-host-port-format","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}