sgl-project/sglang · error · ValueError
Missing port in address (expected host:port): {addr!r}
Error message
Missing port in address (expected host:port): {addr!r} What it means
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.
Source
Thrown at python/sglang/srt/utils/network.py:545
# --- 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))
def __str__(self) -> str:
return self.to_host_port_str()
def __repr__(self) -> str:
return f"NetworkAddress({self.host!r}, {self.port})"
View on GitHub (pinned to 0132848349)
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
Example fix
# before
addr = NetworkAddress.parse(host) # host == 'worker-0'
# after
addr = NetworkAddress.parse(f'{host}:{port}') Defensive patterns
Strategy: validation
Validate before calling
def has_host_and_port(addr: str) -> bool:
return bool(addr) and not addr.startswith('[') and ':' in addr Type guard
null
Try / catch
try:
NetworkAddress.parse(addr)
except ValueError as e:
if 'Missing port' in str(e):
addr = f'{addr}:{DEFAULT_PORT}' Prevention
- Never pass a bare hostname to NetworkAddress.parse
- Centralize host+port joining in config code
- Assert ':' in addr in debug builds
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Expected ':port' after closing bracket, got: {rest!r}
- Invalid IPv6 address inside brackets: {host!r}
- Empty host in address: {addr!r}
- Bare IPv6 address without brackets is ambiguous: {addr!r}. U
- a port must be specified in IPv6 address (format: [ipv6]:por
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/59c46bce5382e700.
Report an issue: GitHub.