{"record":{"id":"0d74d227df9e3641","repo":"XX-net/XX-Net","slug":"load-etc-resolv-conf-fail-r","errorCode":null,"errorMessage":"load /etc/resolv.conf fail:%r","messagePattern":"load /etc/resolv\\.conf fail:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/smart_router/local/dns_query.py","lineNumber":179,"sourceCode":"            iplist = []\n            for i in range(4, ipcount * 4 + 4, 4):\n                ip = socket.inet_ntoa(buf[i:i + 4])\n                iplist.append(ip)\n\n        elif os.path.isfile('/etc/resolv.conf'):\n            try:\n                with open('/etc/resolv.conf', 'rb') as fp:\n                    iplist = re.findall(br'(?m)^nameserver\\s+(\\S+)', fp.read())\n\n                xlog.debug(\"DNS resolve servers:%s\", iplist)\n\n                local_ips = g.local_ips\n                for ip in local_ips:\n                    if ip in iplist:\n                        xlog.warn(\"remove local DNS server %s from upstream\", ip)\n                        iplist.remove(ip)\n            except Exception as e:\n                xlog.warn(\"load /etc/resolv.conf fail:%r\", e)\n\n        if not iplist:\n            if g.config.country_code == \"CN\":\n                iplist = [\n                    b\"114.114.114.114\",\n                    b\"114.114.115.115\",\n                    b\"119.29.29.29\",\n                    b\"182.254.118.118\",\n                    b\"223.5.5.5\",\n                    b\"223.6.6.6\",\n                    b\"180.76.76.76\"\n                ]\n            else:\n                iplist = [\n                    b\"1.1.1.1\",\n                    b\"8.8.8.8\",\n                    b\"9.9.9.9\",\n                    b\"208.67.222.222\",","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/dns_query.py#L161-L197","documentation":"This warning is emitted when get_local_dns_server() fails while parsing /etc/resolv.conf to discover the system's local DNS servers. The resolver file is missing, unreadable, or contains entries the parser cannot handle, so the code falls back to hardcoded or configured DNS servers. It is non-fatal: DNS resolution continues using the fallback list.","triggerScenarios":"Running on a host where /etc/resolv.conf does not exist (minimal containers, some macOS setups), has restrictive permissions, or contains malformed nameserver lines; also triggered if the file lists only local IPs that get filtered out and subsequent parsing raises.","commonSituations":"Docker/alpine containers without resolv.conf, chroot/sandboxed environments, systemd-resolved stub resolver oddities, read-only filesystems.","solutions":["Verify /etc/resolv.conf exists and contains a valid 'nameserver x.x.x.x' line","If running in a container, configure DNS (docker --dns 8.8.8.8 or dns: in compose)","Explicitly set the module's DNS server config so fallback IPs are used and the warning is irrelevant","Ensure the process has read permission on /etc/resolv.conf"],"exampleFix":"# before: no resolv.conf in container\n# after (Dockerfile)\nRUN echo 'nameserver 8.8.8.8' > /etc/resolv.conf","handlingStrategy":"fallback","validationCode":"import os\nDNS_CONF = '/etc/resolv.conf'\nif not os.path.exists(DNS_CONF) or not os.access(DNS_CONF, os.R_OK):\n    # supply explicit DNS servers instead of relying on resolv.conf discovery\n    configure_dns_servers(['8.8.8.8', '1.1.1.1'])","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always configure explicit upstream DNS servers in production so the module never depends on /etc/resolv.conf","In containers, set DNS via docker/compose config rather than relying on defaults","Health-check resolver file presence at app startup"],"tags":["dns","resolv-conf","configuration","startup"],"backgroundTag":"resolv-conf-missing","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}