Version
v24.18.0 , v22.22.0 Issue reproduced on both versions.
Platform
Windows 11 24H2 (Build 10.0.26200) x64
Subsystem
No response
What steps will reproduce the bug?
-
Install Node.js (tested with v22.22.0 and v24.18.0) on Windows 11 (Build 10.0.26200).
-
Save the following as repro.js:
const dns = require("node:dns");
console.log("Node:", process.version);
console.log("Servers:", dns.getServers());
dns.lookup("google.com", (err, address) => {
console.log("lookup:", err, address);
});
dns.resolve4("google.com", (err, addresses) => {
console.log("resolve4:", err, addresses);
});
dns.resolveSrv("_mongodb._tcp.cluster0.mongodb.net", (err, records) => {
console.log("resolveSrv:", err, records);
});
- Run:
- Observe the output.
Output
Node: v22.22.0
Servers: [ '127.0.0.1' ]
resolve4:
Error: queryA ECONNREFUSED google.com
resolveSrv:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.mongodb.net
lookup:
null 2404:6800:4013:804::64
How often does it reproduce? Is there a required condition?
The issue reproduces 100% of the time on my machine.
Conditions:
- Windows 11 (Build 10.0.26200)
- Reproduced with Node.js v22.22.0 and v24.18.0
- Occurs regardless of whether I am connected via Wi-Fi or a mobile hotspot.
- No proxy is configured.
- Windows DNS resolution works correctly (
nslookup and Resolve-DnsName both succeed).
dns.getServers() consistently returns ['127.0.0.1'].
dns.lookup() succeeds.
dns.resolve4() and dns.resolveSrv() fail with ECONNREFUSED.
- Calling
dns.setServers(["8.8.8.8", "1.1.1.1"]) before performing DNS resolution makes the issue disappear.
What is the expected behavior? Why is that the expected behavior?
dns.getServers() should return the DNS servers configured by the operating system rather than 127.0.0.1, since Windows is configured to use DHCP-assigned DNS servers.
On my system:
-
ipconfig /all reports:
- IPv4 DNS:
10.219.174.109
- IPv6 DNS:
2409:40c2:8427:7b61::c7
-
nslookup works correctly.
-
Resolve-DnsName works correctly.
-
dns.lookup() works correctly.
Therefore I expect:
dns.getServers() to report the DNS servers configured by Windows.
dns.resolve4() and dns.resolveSrv() to successfully resolve DNS records without requiring an explicit call to dns.setServers().
Instead, dns.getServers() reports ['127.0.0.1'], causing dns.resolve4() and dns.resolveSrv() to fail with ECONNREFUSED.
What do you see instead?
Instead of using the DNS servers configured by Windows, dns.getServers() returns:
As a result:
dns.lookup() succeeds because it uses the operating system's resolver.
dns.resolve4() fails with ECONNREFUSED.
dns.resolveSrv() fails with ECONNREFUSED.
Output:
Node: v22.22.0
Servers:
[ '127.0.0.1' ]
resolve4:
Error: queryA ECONNREFUSED google.com
code: 'ECONNREFUSED'
syscall: 'queryA'
resolveSrv:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.mongodb.net
code: 'ECONNREFUSED'
syscall: 'querySrv'
lookup:
null 2404:6800:4013:804::64
Additionally, calling:
const dns = require("node:dns");
dns.setServers(["8.8.8.8", "1.1.1.1"]);
before the DNS queries immediately resolves the issue:
dns.resolve4() succeeds.
dns.resolveSrv() succeeds.
- MongoDB Atlas connections using
mongodb+srv:// work correctly.
Additional information
The issue disappears if I explicitly configure DNS servers before performing DNS resolution:
const dns = require("node:dns");
dns.setServers(["8.8.8.8", "1.1.1.1"]);
After calling dns.setServers():
dns.resolve4() succeeds.
dns.resolveSrv() succeeds.
- MongoDB Atlas connections using
mongodb+srv:// work normally.
This suggests that the failure is related to the default DNS server configuration returned by dns.getServers(), which reports 127.0.0.1 on my system.
Version
v24.18.0 , v22.22.0 Issue reproduced on both versions.
Platform
Subsystem
No response
What steps will reproduce the bug?
Install Node.js (tested with v22.22.0 and v24.18.0) on Windows 11 (Build 10.0.26200).
Save the following as
repro.js:Output
How often does it reproduce? Is there a required condition?
The issue reproduces 100% of the time on my machine.
Conditions:
nslookupandResolve-DnsNameboth succeed).dns.getServers()consistently returns['127.0.0.1'].dns.lookup()succeeds.dns.resolve4()anddns.resolveSrv()fail withECONNREFUSED.dns.setServers(["8.8.8.8", "1.1.1.1"])before performing DNS resolution makes the issue disappear.What is the expected behavior? Why is that the expected behavior?
dns.getServers()should return the DNS servers configured by the operating system rather than127.0.0.1, since Windows is configured to use DHCP-assigned DNS servers.On my system:
ipconfig /allreports:10.219.174.1092409:40c2:8427:7b61::c7nslookupworks correctly.Resolve-DnsNameworks correctly.dns.lookup()works correctly.Therefore I expect:
dns.getServers()to report the DNS servers configured by Windows.dns.resolve4()anddns.resolveSrv()to successfully resolve DNS records without requiring an explicit call todns.setServers().Instead,
dns.getServers()reports['127.0.0.1'], causingdns.resolve4()anddns.resolveSrv()to fail withECONNREFUSED.What do you see instead?
Instead of using the DNS servers configured by Windows,
dns.getServers()returns:As a result:
dns.lookup()succeeds because it uses the operating system's resolver.dns.resolve4()fails withECONNREFUSED.dns.resolveSrv()fails withECONNREFUSED.Output:
Additionally, calling:
before the DNS queries immediately resolves the issue:
dns.resolve4()succeeds.dns.resolveSrv()succeeds.mongodb+srv://work correctly.Additional information
The issue disappears if I explicitly configure DNS servers before performing DNS resolution:
After calling
dns.setServers():dns.resolve4()succeeds.dns.resolveSrv()succeeds.mongodb+srv://work normally.This suggests that the failure is related to the default DNS server configuration returned by
dns.getServers(), which reports127.0.0.1on my system.