Node.js server fails to bind on ipv6 if ipv4 is not available
未关闭
还没有人认领这个 Issue。
http
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Version
v24.18.1
Platform
Linux ssh2 6.18.43-alwaysdata #1 SMP PREEMPT_DYNAMIC Fri Aug 7 07:39:43 UTC 2026 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
- Run a HTTP server (code below)
- Try to connect to it (via e.g. python, netcat, a browser etc.)
code:
const http = require("http");
const server = http.createServer((req,res)=>{
res.writeHead(200, "Content-Type", "text/plain");
res.write("ok");
res.end();
});
server.listen({ port: 8300 }, ()=> {
console.log("Server is running");
});
I also tried all the following:
server.listen({ port: 8300, host: "::" }, ()=> {
console.log("Server is running");
});
server.listen({ port: 8300, host: "::", ipv6Only: true }, ()=> {
console.log("Server is running");
});
server.listen({ port: 8300, host: "", ipv6Only: true }, ()=> {
console.log("Server is running");
});
server.listen({ port: 8300, host: "0.0.0.0", ipv6Only: true }, ()=> {
console.log("Server is running");
});
server.listen({ port: 8300, host: "::1", ipv6Only: true }, ()=> {
console.log("Server is running");
});
server.listen({ port: 8300, host: "" }, ()=> {
console.log("Server is running");
});
server.listen(8300, "::", ()=> {
console.log("Server is running");
});
server.listen(8300, "", ()=> {
console.log("Server is running");
});
// maybe even more i forgot
How often does it reproduce? Is there a required condition?
TCPv4 must not be available on the OS.
For example, netstat -lntp must say this:
netstat: no support for `AF INET (tcp)' on this system.
netstat -lntp6 must not say that, however - instead, it should succeed:
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
What is the expected behavior? Why is that the expected behavior?
The server should be accessible
What do you see instead?
No error is thrown or logged, however, I cannot connect to the server in any imaginable way
Additional information
edit: offensive comment removed by moderator
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在不支持 TCPv4 的 Linux 上使用提供的 HTTP 服务器和各个 listen 变体重现该问题,然后跟踪 server.listen 的网络路径。通过验证 IPv6-only 服务器变得可访问,并验证现有的 listen 行为在相关网络测试中仍然正确,来确认修复有效。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, node.js
- 领域
- backend, networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100