nodejs / nodejs/node

Node.js server fails to bind on ipv6 if ipv4 is not available

Aperta
#65,400 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

http
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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?
  1. Run a HTTP server (code below)
  2. 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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema con il server HTTP fornito e le varianti di listen su Linux senza supporto per TCPv4, quindi traccia il percorso di rete di server.listen. Conferma la correzione verificando che un server IPv6-only diventi raggiungibile e che il comportamento esistente di listen rimanga corretto nei test di rete pertinenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
backend, networking
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.