iflytek/astron-agent · error · Exception
failed to get local ip, err reason
Error message
failed to get local ip, err reason %s
What it means
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.
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
Example fix
// before
ip = get_host_ip()
// after
import os
ip = os.getenv("HOST_IP") or get_host_ip() # allow explicit override in isolated networks Defensive patterns
Strategy: fallback
Validate before calling
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(3)
try:
s.connect(("8.8.8.8", 80))
reachable = True
except OSError:
reachable = False
finally:
s.close() Try / catch
try:
ip = get_host_ip()
except Exception as e:
logger.warning("ip detection failed: %s; using configured fallback", e)
ip = os.getenv("HOST_IP", "127.0.0.1") Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/096510c68d46fd03.
Report an issue: GitHub.
Appendix: source
Thrown at core/plugin/link/utils/sid/sid_generator2.py:59
sub = os.getenv(const.SERVICE_SUB_KEY)
location = os.getenv(const.SERVICE_LOCATION_KEY)
local_port = os.getenv(const.SERVICE_PORT_KEY)
local_ip = get_host_ip()
init_sid(sub, location, local_ip, local_port)
def get_host_ip() -> str:
"""
description: Query local IP
"""
s = None
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(3)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
except Exception as err:
raise Exception("failed to get local ip, err reason %s" % str(err))
finally:
if s is not None:
s.close()
return ip
def init_sid(
sub: Optional[str],
location: Optional[str],
local_ip: str,
local_port: Optional[str],
) -> None:
"""Initialize the global SID generator with service configuration.
Args:
sub: Service subsystem identifier
location: Service location identifierView on GitHub (pinned to 5e758547a8)