sgl-project/sglang · error · ValueError

Empty address string

Error message

Empty address string

What it means

NetworkAddress.parse requires a non-empty address string; an empty/whitespace input (or None coerced to '') raises ValueError('Empty address string') before any parsing branch runs.

Source

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

    @staticmethod
    def parse(addr: str) -> NetworkAddress:
        """Parse a ``host:port`` string into a ``NetworkAddress``.

        Accepted formats::

            [::1]:8000          → NetworkAddress("::1", 8000)
            127.0.0.1:8000      → NetworkAddress("127.0.0.1", 8000)
            my-hostname:8000    → NetworkAddress("my-hostname", 8000)

        IPv6 addresses **must** be bracketed.  Bare ``::1:8000`` is
        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:

View on GitHub (pinned to 0132848349)

Solutions

  1. Default the value before parsing: addr_str or "127.0.0.1:0".
  2. Fail fast on missing config at startup with a clear message.
  3. Trim/validate config strings before reaching parse.

Example fix

# before
NetworkAddress.parse(os.environ.get("DIST_ADDR", ""))

# after
NetworkAddress.parse(os.environ.get("DIST_ADDR") or "127.0.0.1:8000")
Defensive patterns

Strategy: validation

Validate before calling

addr = (os.environ.get("DIST_ADDR") or "").strip()
if not addr:
    raise SystemExit("DIST_ADDR is required")

Type guard

def is_nonempty_addr(s) -> bool:
    return isinstance(s, str) and bool(s.strip())

Prevention

When it happens

Trigger: parse("") or parse(os.environ.get("SGLANG_ADDR", "")) where the env var is unset/empty.

Common situations: Optional env vars not set and defaults wired as empty strings; templated config producing blank endpoints.

Related errors


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