{"record":{"id":"00d9abf460cd4d58","repo":"denoland/deno","slug":"cannot-specify-two-ipv4-addresses","errorCode":null,"errorMessage":"Cannot specify two IPv4 addresses","messagePattern":"Cannot specify two IPv4 addresses","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal_binding/cares_wrap.ts","lineNumber":932,"sourceCode":"    //\n    // We validate the addresses here and record them so the call no longer\n    // throws and matches Node's observable behavior. The underlying resolver op\n    // (`op_dns_resolve`) does not yet expose a per-query bind address, so the\n    // stored value is not applied to outgoing queries; see\n    // https://github.com/denoland/deno/issues/36518.\n    let type0: 4 | 6;\n    if (isIPv4(addr0)) {\n      type0 = 4;\n    } else if (isIPv6(addr0)) {\n      type0 = 6;\n    } else {\n      throw new Error(`Invalid IP address: ${addr0}`);\n    }\n\n    if (addr1 !== undefined) {\n      if (isIPv4(addr1)) {\n        if (type0 === 4) {\n          throw new Error(\"Cannot specify two IPv4 addresses\");\n        }\n      } else if (isIPv6(addr1)) {\n        if (type0 === 6) {\n          throw new Error(\"Cannot specify two IPv6 addresses\");\n        }\n      } else {\n        throw new Error(`Invalid IP address: ${addr1}`);\n      }\n    }\n\n    this.#localAddress = {\n      ipv4: type0 === 4 ? addr0 : addr1,\n      ipv6: type0 === 6 ? addr0 : addr1,\n    };\n  }\n\n  cancel() {\n    for (const req of new SafeSetIterator(this.#pendingQueries)) {","sourceCodeStart":914,"sourceCodeEnd":950,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/node/polyfills/internal_binding/cares_wrap.ts#L914-L950","documentation":"ChannelWrap allows binding at most one IPv4 and one IPv6 local address. When the primary address (addr0) is already IPv4 and the secondary address (addr1) is also IPv4, the local-address pair is ambiguous for c-ares, so this error is thrown.","triggerScenarios":"Calling a ChannelWrap lookup with two local addresses where both addr0 and addr1 are valid IPv4 literals, e.g. localAddress '10.0.0.1' plus a second address that is also IPv4.","commonSituations":"Configuration that supplies a list of local addresses where the intent was one IPv4 + one IPv6 but both values happen to be IPv4 (e.g. dual NICs on the same family).","solutions":["Supply at most one IPv4 and one IPv6 local address (one of each family).","Ensure the IPv6 entry is a real IPv6 literal, not another IPv4 address.","Drop the duplicate-family address from the localAddress configuration."],"exampleFix":"// before\nnew ChannelWrap('0.0.0.0', '10.0.0.2'); // two IPv4\n// after\nnew ChannelWrap('0.0.0.0', '::'); // one IPv4 + one IPv6","handlingStrategy":"validation","validationCode":"function validLocalPair(addr0, addr1) {\n  if (addr1 === undefined) return true;\n  return !(isIPv4(addr0) && isIPv4(addr1));\n}\nif (!validLocalPair(a, b)) throw new Error('localAddresses must contain at most one IPv4 and one IPv6');","typeGuard":"function isSingleFamilyPair(a, b) {\n  return b === undefined || (isIPv4(a) !== isIPv4(b));\n}","tryCatchPattern":"try {\n  channel.lookup(req, hostname);\n} catch (err) {\n  if (err.message === 'Cannot specify two IPv4 addresses') {\n    // retry with only the first local address\n  }\n}","preventionTips":["Deduplicate configured addresses by family before passing them in.","Keep at most two entries: one IPv4, one IPv6.","Assert the pair at config validation time, not at lookup time."],"tags":["dns","node-compat","validation"],"backgroundTag":"invalid-ip-address","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-09-03T14:18:07.398Z","contentChangedAt":"2026-09-03T14:18:07.398Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}