{"record":{"id":"096510c68d46fd03","repo":"iflytek/astron-agent","slug":"failed-to-get-local-ip-err-reason-s","errorCode":null,"errorMessage":"failed to get local ip, err reason %s","messagePattern":"failed to get local ip, err reason (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"core/plugin/link/utils/sid/sid_generator2.py","lineNumber":59,"sourceCode":"    sub = os.getenv(const.SERVICE_SUB_KEY)\n    location = os.getenv(const.SERVICE_LOCATION_KEY)\n    local_port = os.getenv(const.SERVICE_PORT_KEY)\n    local_ip = get_host_ip()\n    init_sid(sub, location, local_ip, local_port)\n\n\ndef get_host_ip() -> str:\n    \"\"\"\n    description: Query local IP\n    \"\"\"\n    s = None\n    try:\n        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n        s.settimeout(3)\n        s.connect((\"8.8.8.8\", 80))\n        ip = s.getsockname()[0]\n    except Exception as err:\n        raise Exception(\"failed to get local ip, err reason %s\" % str(err))\n    finally:\n        if s is not None:\n            s.close()\n\n    return ip\n\n\ndef init_sid(\n    sub: Optional[str],\n    location: Optional[str],\n    local_ip: str,\n    local_port: Optional[str],\n) -> None:\n    \"\"\"Initialize the global SID generator with service configuration.\n\n    Args:\n        sub: Service subsystem identifier\n        location: Service location identifier","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/plugin/link/utils/sid/sid_generator2.py#L41-L77","documentation":"get_host_ip determines the machine's local IP by opening a UDP socket and 'connecting' to 8.8.8.8:80, then reading getsockname(). If socket creation, timeout, or connect fails, the original exception is re-raised as 'failed to get local ip, err reason %s'. This is used to build the SID (session ID) generator.","triggerScenarios":"No network route to 8.8.8.8 (air-gapped or firewalled host); DNS/socket failures in restricted containers; socket timeout of 3s exceeded; IPv6-only environments where AF_INET to 8.8.8.8 is unreachable.","commonSituations":"Running the link plugin in an offline/internal cluster with no outbound internet; containers without network egress; firewalls blocking UDP to 8.8.8.8; host networking misconfigured at startup.","solutions":["Ensure outbound UDP connectivity (or any route) from the host; 8.8.8.8 is only used for routing, no packets need to be delivered","Allow egress to 8.8.8.8:80 or to any gateway address in firewall rules","Replace the detection with a configured host IP (env var) or a probe against an internal address like the gateway","Check container runtime network settings (--network) and that the container has an IPv4 address"],"exampleFix":"// before\nip = get_host_ip()\n// after\nimport os\nip = os.getenv(\"HOST_IP\") or get_host_ip()  # allow explicit override in isolated networks","handlingStrategy":"fallback","validationCode":"import socket\ns = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\ns.settimeout(3)\ntry:\n    s.connect((\"8.8.8.8\", 80))\n    reachable = True\nexcept OSError:\n    reachable = False\nfinally:\n    s.close()","typeGuard":null,"tryCatchPattern":"try:\n    ip = get_host_ip()\nexcept Exception as e:\n    logger.warning(\"ip detection failed: %s; using configured fallback\", e)\n    ip = os.getenv(\"HOST_IP\", \"127.0.0.1\")","preventionTips":["Provide an explicit HOST_IP env var for air-gapped or firewalled deployments","Ensure container networking allows outbound UDP to 8.8.8.8 (routing probe only)","Monitor startup logs for repeated ip-detection failures"],"tags":["network","socket","ip","sid"],"backgroundTag":"network-request-failed","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}