{"record":{"id":"46d6b735832a198a","repo":"sgl-project/sglang","slug":"empty-host-in-address-addr-r","errorCode":null,"errorMessage":"Empty host in address: {addr!r}","messagePattern":"Empty host in address: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":548,"sourceCode":"            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\ndef resolve_base_url(base_url: str, host: str, port: int) -> str:\n    \"\"\"Base URL a client sends to: ``base_url`` if set, else ``http://host:port``\n    (IPv6-correct via :class:`NetworkAddress`).\"\"\"","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L530-L566","documentation":"NetworkAddress.parse split the address on the last ':' and found an empty host portion, e.g. ':8080'. The parser refuses addresses that specify a port but no host.","triggerScenarios":"NetworkAddress.parse(':8080'), '::8080' where the host side after rsplit is empty (e.g. ':' + port with a stray leading colon like ': :8080' trimmed to ':8080').","commonSituations":"Template strings like f':{port}' when the host variable is empty/None rendered as '', or misformatted configs with a leading colon.","solutions":["Supply an explicit host: '0.0.0.0:8080'","Check the host variable for empty/None before formatting the address","Use '::' as host only inside brackets ('[::]:8080') for IPv6 wildcard"],"exampleFix":"# before\naddr = NetworkAddress.parse(f'{host}:{port}')  # host == ''\n# after\nhost = host or '0.0.0.0'\naddr = NetworkAddress.parse(f'{host}:{port}')","handlingStrategy":"validation","validationCode":"def has_nonempty_host(addr: str) -> bool:\n    host = addr.rsplit(':', 1)[0]\n    return bool(host.strip())","typeGuard":"null","tryCatchPattern":"try:\n    NetworkAddress.parse(addr)\nexcept ValueError as e:\n    if 'Empty host' in str(e):\n        addr = '0.0.0.0' + addr","preventionTips":["Default empty hosts to '0.0.0.0' at config load","Fail fast when host env vars are unset/empty","Strip stray leading colons from templated strings"],"tags":["network","address-parsing","hostname","sglang"],"backgroundTag":"invalid-host-port-format","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}