{"record":{"id":"010969f42220ea4a","repo":"docmirror/dev-sidecar","slug":"action-hostname-dns-returned-invalid","errorCode":null,"errorMessage":"----- ${action}: ${hostname}, dns returned invalid ip ","messagePattern":"----- (.+?): (.+?), dns returned invalid ip ","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js","lineNumber":109,"sourceCode":"      dns.lookup(hostname, { ipChecker, family }).then((ip) => {\n        if (ip !== hostname && isValidIpAddress(ip)) {\n          const addressFamily = getAddressFamily(ip)\n          if (isDnsIntercept) {\n            isDnsIntercept.dns = dns\n            isDnsIntercept.hostname = hostname\n            isDnsIntercept.ip = ip\n            if (tester) isDnsIntercept.tester = tester\n          }\n          log.info(`----- ${action}: ${hostname}, use ip from dns '${dns.dnsName}': ${ip}(family: ${addressFamily})${target} -----`)\n          if (res) {\n            const dnsLabel = dns.dnsName === '预设IP' ? 'PreSet' : safeHeaderValue(dns.dnsName)\n            res.setHeader('DS-DNS-Lookup', `DNS: ${ip} (IPv${addressFamily}) ${dnsLabel}`)\n          }\n          respondLookup(callback, ip, addressFamily, all)\n        } else {\n          // 使用默认dns\n          if (ip != null && ip !== hostname && !isValidIpAddress(ip)) {\n            log.warn(`----- ${action}: ${hostname}, dns returned invalid ip '${ip}'${target}, fallback to default DNS`)\n          }\n          log.info(`----- ${action}: ${hostname}, use default DNS: ${hostname}${target}, options:`, options, ', dns:', dns)\n          defaultDns.lookup(hostname, options, callback)\n        }\n      }).catch((err) => {\n        log.error(`----- ${action}: ${hostname}, dns lookup error${target}, options:`, options, `, error:`, err)\n        defaultDns.lookup(hostname, options, callback)\n      })\n    }\n  },\n}\n","sourceCodeStart":91,"sourceCodeEnd":121,"githubUrl":"https://github.com/docmirror/dev-sidecar/blob/7710cd56cce760c708f30b01d2d4056eb8c402d5/packages/mitmproxy/src/lib/proxy/mitmproxy/dnsLookup.js#L91-L121","documentation":"The custom lookup function created by createLookupFunc asks the configured DNS for the hostname. If the DNS result is non-null, differs from the hostname, but is not a valid IP address (isValidIpAddress fails), the value is treated as garbage: a warning is logged and the lookup falls back to Node's default DNS for that request, so resolution still succeeds.","triggerScenarios":"A DNS module (preset ip list, DoH provider, custom dnsMap entry) returns a string that is not an IPv4/IPv6 literal — e.g. a preset list containing a domain name, a truncated/annotated IP, or DoH answer data in unexpected format.","commonSituations":"Hand-edited pre-set ip files where someone put hostnames or 'ip:port' strings; third-party DoH services returning CNAME-formatted data handled incorrectly; corrupted user config under ~/.dev-sidecar.","solutions":["Inspect the DNS/ip list for the offending hostname and correct entries to be plain IPv4/IPv6 literals.","Remove the bad preset ip entry so the request uses default or another DNS backend.","Reset the DNS config to shipped defaults and re-apply your customizations one at a time to find the invalid value.","No action strictly required — the code already falls back to default DNS; fix the config to stop losing the speed/availability benefits of custom DNS."],"exampleFix":"// before (preset ips)\n[\"github.com\", \"140.82.112.3\"]\n// after\n[\"140.82.112.3\", \"140.82.113.4\"]","handlingStrategy":"validation","validationCode":"const bad = presetIps.filter(ip => !/^(\\d{1,3}(\\.\\d{1,3}){3}|[0-9a-fA-F:]+)$/.test(ip))\nif (bad.length) console.error('remove invalid ips:', bad)","typeGuard":"const isValidIpAddress = (s) => typeof s === 'string' && (/^(\\d{1,3}\\.){3}\\d{1,3}$/.test(s) || s.includes(':'))","tryCatchPattern":null,"preventionTips":["Keep preset ip lists strictly as IP literals — no hostnames or ip:port strings","Validate user-edited DNS config after every manual change","Reset to default DNS config when resolution misbehaves, then re-customize incrementally"],"tags":["dns","validation","fallback","proxy"],"backgroundTag":"invalid-dns-response","analyzedSha":"7710cd56cce760c708f30b01d2d4056eb8c402d5","analyzedAt":"2026-08-31T22:07:07.234Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}