-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection #61453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
|
Do you think you could add a tests so we don't see this regression again in the future? Thanks! |
Absolutely, happy to add a test. Did you have a specific scenario in mind, or should I just cover the case from the original bug report? |
|
Sure, I've added regression tests for this! Created two test files: test-dns-resolvesrv.js- basic SRV resolution tests |
addaleax
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @NotVivek12! This largely looks good, just have two questions here
| TEST(HelloWorldTest, BasicAssertions) { | ||
| EXPECT_EQ(1 + 1, 2); | ||
| EXPECT_TRUE(true); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^ This file was included unintentionally, right?
| static const unsigned char kIPv6Loopback[16] = | ||
| {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}; | ||
| is_loopback = | ||
| (memcmp(&servers[0].addr.addr6, kIPv6Loopback, sizeof(kIPv6Loopback)) == 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check for host/network byte order conversion here like we do for IPv4 (via htonl)?
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61453 +/- ##
==========================================
+ Coverage 89.78% 89.79% +0.01%
==========================================
Files 672 672
Lines 203809 203814 +5
Branches 39183 39179 -4
==========================================
+ Hits 182980 183020 +40
+ Misses 13166 13113 -53
- Partials 7663 7681 +18
🚀 New features to boost your workflow:
|
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