{"record":{"id":"af8d9fd1997724ca","repo":"sgl-project/sglang","slug":"can-not-get-local-ip","errorCode":null,"errorMessage":"Can not get local ip","messagePattern":"Can not get local ip","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/network.py","lineNumber":374,"sourceCode":"        2. Network interface enumeration via get_local_ip_by_nic()\n        3. Remote connection method via get_local_ip_by_remote()\n    \"\"\"\n    # Try environment variable\n    host_ip = os.getenv(\"SGLANG_HOST_IP\", \"\") or os.getenv(\"HOST_IP\", \"\")\n    if host_ip:\n        return host_ip\n    logger.debug(\"get_ip failed\")\n    # Fallback\n    if ip := get_local_ip_by_nic():\n        return ip\n    logger.debug(\"get_local_ip_by_nic failed\")\n    # Fallback\n    if ip := get_local_ip_by_remote():\n        return ip\n    logger.debug(\"get_local_ip_by_remote failed\")\n    if fallback:\n        return fallback\n    raise ValueError(\"Can not get local ip\")\n\n\ndef get_zmq_socket(\n    context: zmq.Context,\n    socket_type: zmq.SocketType,\n    endpoint: Optional[str] = None,\n    bind: bool = True,\n) -> Union[zmq.Socket, Tuple[int, zmq.Socket]]:\n    \"\"\"Create and configure a ZeroMQ socket.\n\n    Args:\n        context: ZeroMQ context to create the socket from.\n        socket_type: Type of ZeroMQ socket to create.\n        endpoint: Optional endpoint to bind/connect to. If None, binds to a random TCP port.\n        bind: Whether to bind (True) or connect (False) to the endpoint. Ignored if endpoint is None.\n\n    Returns:\n        If endpoint is None: Tuple of (port, socket) where port is the randomly assigned TCP port.","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/network.py#L356-L392","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nip = get_local_ip_auto()  # raises on isolated host\n\n# after\nimport os\nos.environ[\"SGLANG_LOCAL_IP\"] = \"10.0.0.5\"\nip = get_local_ip_auto()","handlingStrategy":"fallback","validationCode":"import socket\n\ndef has_route() -> bool:\n    try:\n        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n        s.connect((\"8.8.8.8\", 80)); s.close(); return True\n    except OSError:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    ip = get_local_ip_auto()\nexcept ValueError:\n    ip = os.environ.get(\"SGLANG_LOCAL_IP\", \"127.0.0.1\")","preventionTips":["Set SGLANG_LOCAL_IP explicitly in containers.","Ensure a default route exists before distributed startup."],"tags":["network","ip","container","distributed"],"backgroundTag":"local-ip-detection-failed","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}