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

The registration order of http server listen depends on the Node.js version #53204

Open
yamachu opened this issue May 29, 2024 · 5 comments
Open
Labels
http Issues or PRs related to the http subsystem. v20.x v20.x Issues that can be reproduced on v20.x or PRs targeting the v20.x-staging branch.

Comments

@yamachu
Copy link

yamachu commented May 29, 2024

Version

v20.13.1

Platform

Darwin 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:16:51 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8103 arm64

Subsystem

No response

What steps will reproduce the bug?

The behavior of Server.listen on the same port has changed between node 20.12 and 20.13.

If you execute code like the following,
In node 20.12, 127.0.0.1:8888 (or 0.0.0.0:8888, localhost:8888) is listened to and the Hello World string is returned.
However, in node 20.13, only 192.168.10.104:8888 is listened to, and the rest, such as 127.0.0.1:8888, are not listened to.

import { createServer } from "node:http";

const server = createServer((_, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Hello World\n");
});

// listen order dependents on the version of node.js...
server.listen(8888, "127.0.0.1"); // 20.13 < , this one is used.
server.listen(8888, "192.168.10.104" /* replace your local ip address */); // 20.13 >= , this one is used.

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

Both will be LISTENED to, or if there is a specification for the order, that document will be clearly noted.

What do you see instead?

no outputs

Additional information

For example, this is how it is used.
https://github.com/Azure/static-web-apps-cli/blob/352be8f4ce2d01e1dac17797a80f9f414d612bc0/src/msha/server.ts#L173-L174

@RedYetiDev RedYetiDev added the http Issues or PRs related to the http subsystem. label May 29, 2024
@RedYetiDev
Copy link
Member

@nodejs/http

@RedYetiDev RedYetiDev added the v20.x v20.x Issues that can be reproduced on v20.x or PRs targeting the v20.x-staging branch. label May 29, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented May 29, 2024

Reference: Azure/static-web-apps-cli#829

Looking at the changelogs between 20.12.2 and 20.13.0, I don't see anything that directly says it changed this functionality, but the following commit might be of interest: #52492 . I'm not sure, but it's involving DNS ordering, so it might be worth a look.

Changelog: https://nodejs.org/en/blog/release/v20.13.0

@theanarkh
Copy link
Contributor

theanarkh commented May 30, 2024

I think this is related to this, this PR makes the last listen is valid. Before this PR, the follow code just listen to 127.0.0.1(I think that's not right it should listen to 192.168.10.104) instead of both. Maybe we should update the docs.

server.listen(8888, "127.0.0.1"); // 20.13 < , this one is used.
server.listen(8888, "192.168.10.104" /* replace your local ip address */); // 20.13 >= , this one is used.

@RedYetiDev
Copy link
Member

I think this is related to this. this PR makes the last listen is valid. Before this PR, the follow code just listen to 127.0.0.1 instead of both. I think that's not right, maybe we should update the docs.

server.listen(8888, "127.0.0.1"); // 20.13 < , this one is used.

server.listen(8888, "192.168.10.104" /* replace your local ip address */); // 20.13 >= , this one is used.

Ahh that makes more sense

@mcollina
Copy link
Member

I didn't even know multiple .listen() was possible. I think we should just error in this case, or add support for multiple interfaces. In Fastify, we handle it with having multiple server instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. v20.x v20.x Issues that can be reproduced on v20.x or PRs targeting the v20.x-staging branch.
Projects
None yet
Development

No branches or pull requests

4 participants