denoland/deno · error · Error
Cannot specify two IPv6 addresses
Error message
Cannot specify two IPv6 addresses
What it means
Analogous to the IPv4 case: ChannelWrap accepts at most one local address per address family. If both addr0 and addr1 are valid IPv6 literals, this error is thrown because the pair cannot be mapped onto the single ipv4/ipv6 slot structure used for c-ares.
Source
Thrown at ext/node/polyfills/internal_binding/cares_wrap.ts:936
// stored value is not applied to outgoing queries; see
// https://github.com/denoland/deno/issues/36518.
let type0: 4 | 6;
if (isIPv4(addr0)) {
type0 = 4;
} else if (isIPv6(addr0)) {
type0 = 6;
} else {
throw new Error(`Invalid IP address: ${addr0}`);
}
if (addr1 !== undefined) {
if (isIPv4(addr1)) {
if (type0 === 4) {
throw new Error("Cannot specify two IPv4 addresses");
}
} else if (isIPv6(addr1)) {
if (type0 === 6) {
throw new Error("Cannot specify two IPv6 addresses");
}
} else {
throw new Error(`Invalid IP address: ${addr1}`);
}
}
this.#localAddress = {
ipv4: type0 === 4 ? addr0 : addr1,
ipv6: type0 === 6 ? addr0 : addr1,
};
}
cancel() {
for (const req of new SafeSetIterator(this.#pendingQueries)) {
req.oncomplete("ECANCELLED", []);
}
SetPrototypeClear(this.#pendingQueries);
View on GitHub (pinned to a961cdec3b)
Solutions
- Pass one IPv6 and one IPv4 address, not two IPv6 addresses.
- Filter the address list so only the first address of each family is used.
- Remove the redundant IPv6 address from the localAddress options.
Example fix
// before
new ChannelWrap('::1', 'fe80::1'); // two IPv6
// after
new ChannelWrap('::1', '0.0.0.0'); // one IPv6 + one IPv4 Defensive patterns
Strategy: validation
Validate before calling
if (isIPv6(addr0) && isIPv6(addr1)) {
throw new Error('Provide at most one IPv6 local address');
} Type guard
function atMostOneIpv6(a, b) {
return !(b !== undefined && isIPv6(a) && isIPv6(b));
} Try / catch
try {
channel.lookup(req, hostname);
} catch (err) {
if (err.message === 'Cannot specify two IPv6 addresses') {
// drop the second IPv6 address and retry
}
} Prevention
- Filter interface address lists to the first address per family.
- Normalize config so localAddresses is always [ipv4?, ipv6?] in that order.
- Unit-test address-pair assembly from multi-NIC configurations.
When it happens
Trigger: Calling a ChannelWrap lookup with two local addresses where addr0 is IPv6 and addr1 is also an IPv6 literal (e.g. '::' and '::1').
Common situations: Misconfigured multi-homed setups passing two IPv6 interface addresses as localAddress/localAddresses; scripts that iterate over all interface addresses and pass them all through.
Related errors
- Invalid IP address: ${addr0}
- Cannot specify two IPv4 addresses
- Invalid IP address: ${addr1}
- invalid ${name}, must not be infinity or NaN
- ERR_INVALID_HTTP_TOKEN
AI-assisted analysis of denoland/deno@a961cdec3b (2026-09-03).
Data as JSON: /api/errors/b56f33cc32ac0851.
Report an issue: GitHub.