eclipse-thingweb / eclipse-thingweb/node-wot

CoAP: Client IPv6 support not working with hostnames

Open
#1,454 0 comments 4 reactions 0 assignees View on GitHub
binding-coap bug
Dominant language
TypeScript
Stars
192
Forks
100
Avg merge
3d 2h
Merged PRs (30d)
6

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](https://github.com/eclipse-thingweb/node-wot/blob/master/packages/binding-coap/src/coap-client.ts#L214), where the node-wot CoAP client tries to guess the socket type:

```typescript
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 https://github.com/nodejs/node/issues/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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.