{"record":{"id":"8ed67eaa15ed13ea","repo":"iflytek/astron-agent","slug":"bad-ip-localip","errorCode":null,"errorMessage":"Bad IP !! {localIp}","messagePattern":"Bad IP !! (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/workflow/extensions/otlp/sid/sid_generator2.py","lineNumber":71,"sourceCode":"        :param localIp: Local IP address (must be valid IPv4)\n        :param localPort: Local port number (must be at least 4 characters)\n        :raises ValueError: If IP address is invalid or port is too short\n        \"\"\"\n        # Initialize sequential index counter\n        self.index = 0\n\n        # Parse and validate IP address\n        ip = socket.inet_aton(localIp)\n        if ip:\n            # Extract the last two octets of the IP address\n            ipSec3 = ip[2]\n            ipSec4 = ip[3]\n            ip3 = ipSec3 & 0xFF\n            ip4 = ipSec4 & 0xFF\n            # Create short IP representation using last two octets\n            self.ShortLocalIP = f\"{ip3:02x}{ip4:02x}\"\n        else:\n            raise ValueError(\"Bad IP !! \" + localIp)\n\n        # Validate port number length\n        if len(localPort) < 4:\n            raise ValueError(\"Bad Port!! \")\n\n        # Store configuration parameters\n        self.port = localPort\n        self.location = location\n        self.sub = sub\n        logger.debug(\"✅ SID generator initialized successfully\")\n\n    def gen(self) -> str:\n        \"\"\"\n        Generate a unique session identifier.\n\n        The SID format is: {sub}{pid}{index}@{location}{timestamp}{ip}{port}{version}\n\n        :return: A unique session identifier string","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/extensions/otlp/sid/sid_generator2.py#L53-L89","documentation":"SidGenerator2.__init__ converts localIp via socket.inet_aton and builds a short 4-hex-char IP suffix; if inet_aton cannot parse the string (the else branch is reached only when ip is falsy/invalid) it raises ValueError(\"Bad IP !! <ip>\"). Effectively this means the localIp argument is not a valid dotted-quad IPv4 address (e.g. empty, hostname, or IPv6 string).","triggerScenarios":"Constructing SidGenerator2(sub, location, localIp, localPort) where localIp is empty, a hostname like 'localhost', an IPv6 address, or otherwise not parseable by socket.inet_aton as IPv4.","commonSituations":"Service discovery returning a hostname instead of an IP; env var for the pod IP unset or empty in local development; containerized environments reporting IPv6 or '::1'.","solutions":["Pass a valid dotted-quad IPv4 string (e.g. '10.0.1.23') as localIp — resolve hostnames with socket.gethostbyname first.","Fix the env/config supplying the pod IP (e.g. status.podIP in Kubernetes) so it is not empty or '::1'.","Add a pre-check: socket.inet_aton(localIp) in a try/except before constructing SidGenerator2.","In IPv6-only clusters, ensure the pod advertises an IPv4 address or adapt the generator."],"exampleFix":"// before\ngen = SidGenerator2(sub, loc, os.getenv(\"POD_IP\", \"\"), port)\n// after\nip = os.getenv(\"POD_IP\") or socket.gethostbyname(socket.gethostname())\nsocket.inet_aton(ip)  # fail fast with a clear message\ngen = SidGenerator2(sub, loc, ip, port)","handlingStrategy":"validation","validationCode":"import socket\ndef valid_ipv4(s):\n    try:\n        socket.inet_aton(s)\n        return True\n    except OSError:\n        return False\nassert valid_ipv4(pod_ip), f\"invalid localIp: {pod_ip!r}\"","typeGuard":"def is_ipv4(s):\n    if not isinstance(s, str) or not s:\n        return False\n    try:\n        socket.inet_aton(s)\n        return True\n    except OSError:\n        return False","tryCatchPattern":"try:\n    gen = SidGenerator2(sub, location, local_ip, local_port)\nexcept ValueError as e:\n    logger.error(f\"sid generator config invalid: {e}\")\n    raise","preventionTips":["Always supply the pod IP (status.podIP) rather than a hostname.","Fail fast at startup by constructing SidGenerator2 during boot, not per-request.","Handle IPv6-only clusters by advertising an IPv4 address."],"tags":["validation","configuration","ip-address","observability"],"backgroundTag":"invalid-argument-format","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"}