sgl-project/sglang · error · ValueError
Expected ':port' after closing bracket, got: {rest!r}
Error message
Expected ':port' after closing bracket, got: {rest!r} What it means
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.
Source
Thrown at python/sglang/srt/utils/network.py:538
ambiguous and will raise ``ValueError``.
Raises:
ValueError: If the string cannot be unambiguously parsed.
"""
if not addr:
raise ValueError("Empty address string")
# --- Bracketed IPv6: [addr]:port ---
if addr.startswith("["):
close = addr.find("]")
if close == -1:
raise ValueError(f"Missing closing bracket in IPv6 address: {addr!r}")
host = addr[1:close]
if not _is_ipv6(host):
raise ValueError(f"Invalid IPv6 address inside brackets: {host!r}")
rest = addr[close + 1 :]
if not rest.startswith(":") or len(rest) < 2:
raise ValueError(
f"Expected ':port' after closing bracket, got: {rest!r}"
)
return NetworkAddress(host, _parse_port(rest[1:]))
# --- Plain host:port (IPv4 / hostname) ---
if ":" not in addr:
raise ValueError(f"Missing port in address (expected host:port): {addr!r}")
host, port_str = addr.rsplit(":", 1)
if not host:
raise ValueError(f"Empty host in address: {addr!r}")
# Guard against bare IPv6 slipping through
if ":" in host and _is_ipv6(host):
raise ValueError(
f"Bare IPv6 address without brackets is ambiguous: {addr!r}. "
f"Use [{host}]:{port_str} instead."
)
return NetworkAddress(host, _parse_port(port_str))
View on GitHub (pinned to 0132848349)
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
Example fix
# before
addr = NetworkAddress.parse('[::1]')
# after
addr = NetworkAddress.parse('[::1]:8080') Defensive patterns
Strategy: validation
Validate before calling
import re
def has_ipv6_port(addr: str) -> bool:
m = re.match(r'^\[[^\]]+\](:.+)?$', addr or '')
return m is not None and bool(m.group(1)) and len(m.group(1)) > 1 Type guard
null
Try / catch
try:
NetworkAddress.parse(addr)
except ValueError as e:
if 'after closing bracket' in str(e):
addr = addr + ':8080' # apply default port and retry Prevention
- Always build addresses as f'[{ipv6}]:{port}'
- Regex-validate bracketed addresses before parse
- Reject trailing whitespace in config values
When it happens
Trigger: NetworkAddress.parse('[::1]'), '[::1]:', '[::1]8080', or '[::1]/24:8080'.
Common situations: Copy-pasting bare IPv6 literals without appending a port, or config values where the port was stripped or separated by whitespace.
Related errors
- Invalid IPv6 address inside brackets: {host!r}
- Missing port in address (expected host:port): {addr!r}
- Bare IPv6 address without brackets is ambiguous: {addr!r}. U
- a port must be specified in IPv6 address (format: [ipv6]:por
- Empty host in address: {addr!r}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/9b9f0f61911e537a.
Report an issue: GitHub.