You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The registration order of http server listen depends on the Node.js version #53204
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";constserver=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.
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.
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.
Reacted by Aviv Keller, Yusuke Yamada and Marco Ippolito
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.
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.
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Activity
avivkeller commentedon May 29, 2024
@nodejs/http
avivkeller commentedon 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 commentedon May 30, 2024
I think this is related to this, this PR makes the last
listenis valid. Before this PR, the follow code just listen to127.0.0.1(I think that's not right it should listen to192.168.10.104) instead of both. Maybe we should update the docs.avivkeller commentedon May 30, 2024
Ahh that makes more sense
mcollina commentedon May 30, 2024
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.github-actions commentedon Jul 31, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.
brynary commentedon Aug 30, 2026
This issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.