{"record":{"id":"9b9f0f61911e537a","repo":"sgl-project/sglang","slug":"expected-port-after-closing-bracket-got-rest","errorCode":null,"errorMessage":"Expected ':port' after closing bracket, got: {rest!r}","messagePattern":"Expected ':port' after closing bracket, got: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":538,"sourceCode":"        ambiguous and will raise ``ValueError``.\n\n        Raises:\n            ValueError: If the string cannot be unambiguously parsed.\n        \"\"\"\n        if not addr:\n            raise ValueError(\"Empty address string\")\n\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","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L520-L556","documentation":"NetworkAddress.parse found a closing ']' in the address but the remainder after it is not a ':port' suffix (either it does not start with ':' or is just ':' with no digits). Bracketed IPv6 addresses must be followed immediately by a colon and a port number.","triggerScenarios":"NetworkAddress.parse('[::1]'), '[::1]:', '[::1]8080', or '[::1]/24:8080'.","commonSituations":"Copy-pasting bare IPv6 literals without appending a port, or config values where the port was stripped or separated by whitespace.","solutions":["Append ':<port>' directly after the bracket: '[::1]:8080'","Check for stray characters or whitespace between ']' and ':'","Validate address strings with a regex like ^\\[[0-9a-fA-F:]+\\]:\\d+$ before passing them in"],"exampleFix":"# before\naddr = NetworkAddress.parse('[::1]')\n# after\naddr = NetworkAddress.parse('[::1]:8080')","handlingStrategy":"validation","validationCode":"import re\ndef has_ipv6_port(addr: str) -> bool:\n    m = re.match(r'^\\[[^\\]]+\\](:.+)?$', addr or '')\n    return m is not None and bool(m.group(1)) and len(m.group(1)) > 1","typeGuard":"null","tryCatchPattern":"try:\n    NetworkAddress.parse(addr)\nexcept ValueError as e:\n    if 'after closing bracket' in str(e):\n        addr = addr + ':8080'  # apply default port and retry","preventionTips":["Always build addresses as f'[{ipv6}]:{port}'","Regex-validate bracketed addresses before parse","Reject trailing whitespace in config values"],"tags":["network","ipv6","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"}