sgl-project/sglang · error · ValueError
Can not get local ip
Error message
Can not get local ip
What it means
get_local_ip_auto tries several strategies (configured IP, NIC lookup, UDP-socket trick to a remote resolver) to determine the host IP. If all fail and no fallback value was supplied, it raises ValueError('Can not get local ip') — the machine effectively has no usable outbound network path.
Source
Thrown at python/sglang/srt/utils/network.py:374
2. Network interface enumeration via get_local_ip_by_nic()
3. Remote connection method via get_local_ip_by_remote()
"""
# Try environment variable
host_ip = os.getenv("SGLANG_HOST_IP", "") or os.getenv("HOST_IP", "")
if host_ip:
return host_ip
logger.debug("get_ip failed")
# Fallback
if ip := get_local_ip_by_nic():
return ip
logger.debug("get_local_ip_by_nic failed")
# Fallback
if ip := get_local_ip_by_remote():
return ip
logger.debug("get_local_ip_by_remote failed")
if fallback:
return fallback
raise ValueError("Can not get local ip")
def get_zmq_socket(
context: zmq.Context,
socket_type: zmq.SocketType,
endpoint: Optional[str] = None,
bind: bool = True,
) -> Union[zmq.Socket, Tuple[int, zmq.Socket]]:
"""Create and configure a ZeroMQ socket.
Args:
context: ZeroMQ context to create the socket from.
socket_type: Type of ZeroMQ socket to create.
endpoint: Optional endpoint to bind/connect to. If None, binds to a random TCP port.
bind: Whether to bind (True) or connect (False) to the endpoint. Ignored if endpoint is None.
Returns:
If endpoint is None: Tuple of (port, socket) where port is the randomly assigned TCP port.View on GitHub (pinned to 0132848349)
Solutions
- Set SGLANG_LOCAL_IP (or SGLANG_LOCAL_IP_NIC with netifaces installed) to the bind IP explicitly.
- Fix the container/host networking so a default route to the bootstrap address exists.
- If calling get_local_ip_auto programmatically, pass fallback="127.0.0.1" for single-node runs.
Example fix
# before ip = get_local_ip_auto() # raises on isolated host # after import os os.environ["SGLANG_LOCAL_IP"] = "10.0.0.5" ip = get_local_ip_auto()
Defensive patterns
Strategy: fallback
Validate before calling
import socket
def has_route() -> bool:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)); s.close(); return True
except OSError:
return False Try / catch
try:
ip = get_local_ip_auto()
except ValueError:
ip = os.environ.get("SGLANG_LOCAL_IP", "127.0.0.1") Prevention
- Set SGLANG_LOCAL_IP explicitly in containers.
- Ensure a default route exists before distributed startup.
When it happens
Trigger: Running on an isolated/air-gapped host or a container with no default route, so connecting a UDP socket to the bootstrap/remote address fails, and no SGLANG_LOCAL_IP/NIC env or fallback argument is provided.
Common situations: Docker/K8s pods with restricted networking, CI runners without external access, misconfigured hosts where DNS/route is down. Hits engine init, encoder bootstrap registration, and mooncake transfer-engine init.
Related errors
- invalid IPv6 address format: missing ']'
- invalid IPv6 address: {host}
- received IPv6 address format: expected ':' after ']'
- a port must be specified in IPv6 address (format: [ipv6]:por
- Cannot resolve host {host!r}: {e}
AI-assisted analysis of sgl-project/sglang@0132848349 (2026-08-28).
Data as JSON: /api/errors/af8d9fd1997724ca.
Report an issue: GitHub.