Version: Deno 2.8.1
Hi,
I would like to report a behavior in Deno that can be reproduced using the below snippet:
import dns from 'node:dns';
import net from 'node:net';
// dns.lookup callback style to mirror original behavior
dns.lookup('localhost', (err, address, family) => {
console.log(err, address, family);
const server = net.createServer();
server.listen(3000, 'localhost', () => {
console.log(JSON.stringify(server.address()));
server.close(() => {
// In Node this exits the process; in Deno it just ends the script
if (typeof process !== 'undefined' && process.exit) {
process.exit(0);
}
});
});
});
Expected behavior
root@KContainer:~/4341# node bug.mjs
null ::1 6
{"address":"::1","family":"IPv6","port":3000}
Actual behavior
When running Node-style networking code under Deno’s Node compatibility layer, localhost resolves differently compared to Node.js, leading to different IP versions being used for DNS lookup and TCP server binding.
root@KContainer:~/4341# deno run -A bug.mjs
null 127.0.0.1 4
{"address":"127.0.0.1","port":3000,"family":"IPv4"}
Version: Deno 2.8.1
Hi,
I would like to report a behavior in Deno that can be reproduced using the below snippet:
Expected behavior
Actual behavior
When running Node-style networking code under Deno’s Node compatibility layer, localhost resolves differently compared to Node.js, leading to different IP versions being used for DNS lookup and TCP server binding.