sgl-project/sglang · error · ValueError

Empty host in address: {addr!r}

Error message

Empty host in address: {addr!r}

What it means

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.

Source

Thrown at python/sglang/srt/utils/network.py:548

            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})"


def resolve_base_url(base_url: str, host: str, port: int) -> str:
    """Base URL a client sends to: ``base_url`` if set, else ``http://host:port``
    (IPv6-correct via :class:`NetworkAddress`)."""

View on GitHub (pinned to 0132848349)

Solutions

  1. Supply an explicit host: '0.0.0.0:8080'
  2. Check the host variable for empty/None before formatting the address
  3. Use '::' as host only inside brackets ('[::]:8080') for IPv6 wildcard

Example fix

# before
addr = NetworkAddress.parse(f'{host}:{port}')  # host == ''
# after
host = host or '0.0.0.0'
addr = NetworkAddress.parse(f'{host}:{port}')
Defensive patterns

Strategy: validation

Validate before calling

def has_nonempty_host(addr: str) -> bool:
    host = addr.rsplit(':', 1)[0]
    return bool(host.strip())

Type guard

null

Try / catch

try:
    NetworkAddress.parse(addr)
except ValueError as e:
    if 'Empty host' in str(e):
        addr = '0.0.0.0' + addr

Prevention

When it happens

Trigger: 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').

Common situations: Template strings like f':{port}' when the host variable is empty/None rendered as '', or misformatted configs with a leading colon.

Related errors


AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28). Data as JSON: /api/errors/46d6b735832a198a. Report an issue: GitHub.