{"record":{"id":"6155362c851b1e37","repo":"XX-net/XX-Net","slug":"query-by-system-s-d-e-r","errorCode":null,"errorMessage":"query_by_system %s %d e:%r","messagePattern":"query_by_system (.+?) (.+?) e:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/smart_router/local/dns_query.py","lineNumber":282,"sourceCode":"\n            if utils.check_ip_valid4(server_ip):\n                self.sock.sendto(req4_pack, (server_ip, 53))\n            else:\n                self.sock6.sendto(req4_pack, (server_ip, 53))\n        except Exception as e:\n            xlog.warn(\"send_request except:%r\", e)\n\n    def query_by_system(self, domain, dns_type):\n        ips = []\n        try:\n            t0 = time.time()\n            ip = socket.gethostbyname(domain)\n            t1 = time.time()\n            ips.append(ip)\n\n            xlog.debug(\"query_by_system, %s %d cost:%f, return:%s\", domain, dns_type, t1 - t0, ips)\n        except Exception as e:\n            xlog.warn(\"query_by_system %s %d e:%r\", domain, dns_type, e)\n\n        return ips\n\n    def query(self, domain, dns_type=1, timeout=3):\n        if sys.platform == \"ios\":\n            return self.query_by_system(domain, dns_type)\n\n        t0 = time.time()\n        end_time = t0 + timeout\n        while True:\n            id = random.randint(0, 65535)\n            if id not in self.waiters:\n                break\n\n        que = Queue()\n        que.domain = domain\n\n        for server_ip in self.dns_server:","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/dns_query.py#L264-L300","documentation":"query_by_system() wraps socket.gethostbyname() and logs this warning when the OS resolver fails to resolve the domain. It returns an empty IP list; it does not raise. Causes include NXDOMAIN, resolver timeouts, DNS service down, or an invalid hostname string.","triggerScenarios":"Calling query()/query_by_system() with a non-existent domain (NXDOMAIN), an empty or malformed hostname, or when the host's system resolver (see /etc/resolv.conf, systemd-resolved, mDNS) is unavailable or times out. Also the default path on iOS (sys.platform == 'ios').","commonSituations":"Typos in domain names, testing with fake domains, container/systemd-resolved breakage, macOS/ iOS where gethostbyname goes through mDNSResponder and the network is flaky.","solutions":["Confirm the domain actually resolves: 'nslookup domain' on the same machine","Fix the host's system resolver configuration (/etc/resolv.conf, systemd-resolved status)","Pass a real, fully-qualified domain name; avoid empty strings and trailing junk","If the system resolver is unreliable, route queries through the module's UDP/TCP/DoT/DoH clients instead of query_by_system"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import socket\ndef resolves(domain):\n    try:\n        socket.gethostbyname(domain)\n        return True\n    except socket.gaierror:\n        return False","typeGuard":null,"tryCatchPattern":"ips = dns.query(domain)\nif not ips:  # query_by_system never raises; it returns []\n    handle_unresolvable(domain)","preventionTips":["Validate domain syntax before querying","Treat empty list return as the error signal — this API never raises for resolution failure","On iOS always have a fallback path since query() routes to query_by_system"],"tags":["dns","gethostbyname","system-resolver","nx-domain"],"backgroundTag":"dns-resolution-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}