-
Notifications
You must be signed in to change notification settings - Fork 89
Description
The CoAP client currently cannot communicate with IPv6 servers when using a hostname, e.g., an mDNS .local FQDN. The root cause is with the NodeJS dgram module, which requires the socket type udp4 vs udp6 upfront on socket creation.
The issue is triggered in coap-client.ts#L214, where the node-wot CoAP client tries to guess the socket type:
agentOptions.type = net.isIPv6(requestUri.hostname ?? "") ? "udp6" : "udp4";This only works if the "hostname" is an IPv6 literal, e.g., [fda6:d265:87ea:1:7d73:c431:6147:f57c]. In case hostname is actually a hostname, e.g., my-servient.local, the statement assigns udp4 -- even if my-servient.local resolves to an IPv6 address only (i.e., no A record for that hostname).
The root cause is in the design of the dgram module, which on the one hand requires the type on creation, but on the other hand integrates the support for DNS resolution. This is not only stupid, it also breaks with the design of the NodeJS net module for TCP.
There is a closed issue on the design inconsistency on nodejs/node#33331. I commented on it that there is now a graver issue that calls for fix of this root cause problem. As it is a closed issue, we would probably need to open a new one to get a reaction, but I did not have time to create a small, stand-alone bug reproduction script.
Until NodeJS actually fixes dgram, the node-wot CoAP client probably needs to resolve hostnames first on its own and then pass the resolved IP address to dgram or at least chose the agentOptions.type based on the resolved address instead of the hostname as in line 214.