dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection #61453
+21
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection
Summary
This PR fixes a regression introduced in Node.js v24.13.0 on Windows where DNS SRV lookups (commonly used by MongoDB connection strings) fail with
ECONNREFUSED.The issue stems from a change in
c-aresbehavior where the fallback resolver (loopback) is reported with port 53 rather than port 0. The existing Node.js glue layer strictly expected port 0 to identify a fallback scenario. Consequently, Node.js failed to detect the fallback, attempting to query a non-listening local stub resolver at127.0.0.1:53or[::1]:53.Changes
ChannelWrap::EnsureServers**: Modified logic to treat any single loopback server (IPv4 127.0.0.1 or IPv6 ::1) as a fallback configuration, regardless of the port number reported byc-ares.EnsureServers()immediately before dispatching queries in theQuerytemplate to ensure the channel is correctly initialized before use.Regression Details
Error: querySrv ECONNREFUSEDReproduction
This issue is 100% reproducible on Windows with Node v24.13.0 using the following script (mimicking a standard Mongoose connection):
Output on v24.13.0:
Error: querySrv ECONNREFUSED _mongodb._tcp.cluster0.example.mongodb.netManual Verification
dns.getServers()no longer returns a single loopback address when the system resolver is active.Risks
Low.
c-aresdiscovers a single loopback server and the user has not manually calledsetServers().setServers()is called,is_servers_default_becomes false, skipping this check entirely.Workaround for users
Users on v24.13.0 can temporarily work around this by forcing DNS servers before connection:Checklist
dns/c-ares