Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using node:dgram with link-local IPv6 addresses #24694

Open
nathanwhit opened this issue Jul 24, 2024 · 0 comments
Open

Error using node:dgram with link-local IPv6 addresses #24694

nathanwhit opened this issue Jul 24, 2024 · 0 comments
Labels
bug Something isn't working correctly node compat

Comments

@nathanwhit
Copy link
Member

Repro:

import { strictEqual } from "node:assert";
import { createSocket } from "node:dgram";
import { networkInterfaces } from "node:os";
import process from "node:process";

const isWindows = process.platform === "win32";

function linklocal() {
  for (const [ifname, entries] of Object.entries(networkInterfaces())) {
    for (const { address, family, scopeid } of entries) {
      if (family === "IPv6" && address.startsWith("fe80:")) {
        return { address, ifname, scopeid };
      }
    }
  }
}
const iface = linklocal();

if (!iface) {
  process.exit(0);
}

const address = isWindows ? iface.address : `${iface.address}%${iface.ifname}`;
const message = "Hello, local world!";

// Create a client socket for sending to the link-local address.
const client = createSocket("udp6");

// Create the server socket listening on the link-local address.
const server = createSocket("udp6");

server.on(
  "listening",
  () => {
    const port = server.address().port;
    client.send(message, 0, message.length, port, address);
  },
);

server.on(
  "message",
  (buf, info) => {
    const received = buf.toString();
    strictEqual(received, message);
    // Check that the sender address is the one bound,
    // including the link local scope identifier.
    strictEqual(
      info.address,
      isWindows ? `${iface.address}%${iface.scopeid}` : address,
    );
    server.close();
    client.close();
  },
);

server.bind({ address });

Output:

error: Uncaught Error: bind UNKNOWN fe80::1%lo0
    at __node_internal_captureLargerStackTrace (ext:deno_node/internal/errors.ts:93:9)
    at __node_internal_exceptionWithHostPort (ext:deno_node/internal/errors.ts:217:10)
    at node:dgram:273:20
    at Array.processTicksAndRejections (ext:deno_node/_next_tick.ts:36:15)
    at eventLoopTick (ext:core/01_core.js:165:29)

Expect no output, and for the program to exit cleanly.

@nathanwhit nathanwhit added bug Something isn't working correctly node compat labels Jul 24, 2024
nathanwhit added a commit that referenced this issue Jul 24, 2024
…x the ones that fail) (#24631)

The intent is that those tests will be executed, but our check that the
files are up to date won't overwrite the contents of the tests. This is
useful when a test needs some manual edits to work.

It turns out we weren't actually running them.

---

This ended up turning into a couple of small bug fixes to get the tests
passing:

- We weren't canonicalizing the exec path properly (it sometimes still
had `..` or `.` in it)
- We weren't accepting strings in `process.exit`

There was one failure I couldn't figure out quickly, so I disabled the
test for now, and filed a follow up issue: #24694
dsherret pushed a commit that referenced this issue Jul 26, 2024
…x the ones that fail) (#24631)

The intent is that those tests will be executed, but our check that the
files are up to date won't overwrite the contents of the tests. This is
useful when a test needs some manual edits to work.

It turns out we weren't actually running them.

---

This ended up turning into a couple of small bug fixes to get the tests
passing:

- We weren't canonicalizing the exec path properly (it sometimes still
had `..` or `.` in it)
- We weren't accepting strings in `process.exit`

There was one failure I couldn't figure out quickly, so I disabled the
test for now, and filed a follow up issue: #24694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node compat
Projects
None yet
Development

No branches or pull requests

1 participant