dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection#61453
dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection#61453NotVivek12 wants to merge 1 commit into
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.
Thank you @NotVivek12! This largely looks good, just have two questions here
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #61453 +/- ##
=======================================
Coverage 89.74% 89.75%
=======================================
Files 674 674
Lines 204360 204365 +5
Branches 39265 39266 +1
=======================================
+ Hits 183412 183424 +12
+ Misses 13251 13241 -10
- Partials 7697 7700 +3
🚀 New features to boost your workflow:
|
|
@NotVivek12 Can you look at the linter failures? Looks like there's some failing tasks |
Hello, ive made the changes trying to resolve these errors. Hope it works. |
|
Kicked off CI to see how well this does, but we'll probably need to remove |
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - fix fix Windows SRV ECONNREFUSED regression ⚠ - Merge branch 'main' of https://github.com/NotVivek12/node ⚠ - Merge branch 'nodejs:main' into main ⚠ - add regression tests ⚠ - remove unintentional file ⚠ - Merge branch 'nodejs:main' into main ⚠ - Merge branch 'main' of https://github.com/NotVivek12/node ⚠ - fix CI/CD errors ⚠ - Merge branch 'nodejs:main' into main ⚠ - Merge branch 'main' of https://github.com/NotVivek12/node ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/21514988012 |
|
Hi @addaleax i tried looking for what caused these tests to fail and couldnt figure out what the exact issues were, could you please help me figure out what these issues were caused by, so that i could come up with the fix for these. |
addaleax
left a comment
There was a problem hiding this comment.
Sure, let's do another one and see if/where it fails
|
Is this fix cherry picked for Node 22.x series? I have got reports from users on Node 22 happening this problem. |
|
Hello team! Would this be introduced in the LTS version as well? On a separate note, this is also unfortunately affecting mongodb-js/mongosh indirectly on Windows, I believe. Thanks team! |
Thank You so much for doing that for me. |
Newer c-ares versions set tcp_port/udp_port to 53 instead of 0, which caused the loopback detection to fail. This fix: - Removes the port check from loopback detection - Adds IPv6 loopback (::1) support - Calls EnsureServers() before each DNS query PR-URL: #61453 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Newer c-ares versions set tcp_port/udp_port to 53 instead of 0, which caused the loopback detection to fail. This fix: - Removes the port check from loopback detection - Adds IPv6 loopback (::1) support - Calls EnsureServers() before each DNS query PR-URL: #61453 Reviewed-By: Anna Henningsen <anna@addaleax.net>
|
This bug appears to still exist in 24.14.0 for Windows |
|
@NotVivek12 My understanding is that this regression was caused by c-ares/c-ares#1034 which caused c-ares/c-ares#1056. Does that specific c-ares change match up with the behaviour change you described: 'change in c-ares behavior where the fallback resolver (loopback) is reported with port 53'? If so, then I believe this c-ares regression landed in Node when Node bumped the c-ares dep for a security release in January 2026. This c-ares dep bump shipped in v20.20.0, v22.22.0, v24.13.0, and v25.3.0. That means this PR needs to be shipped into v20, v22, v24, and v25. This PR has landed in v24 and v25 but NOT v20 or v22. Yes v20 and v22 are in MAINTENANCE not ACTIVE, but this regression was introduced in a security update, so I think it's reasonable to say that the fix for the regression should also ship to v20 and v22. |
Can confirm I get the same issue when on |
|
Reproduced on Windows 11 with Node v24.14.0 and v22.22.0. Downgrading to v24.11.1 or v22.13.1 fixed the issue. The error was querySrv ECONNREFUSED when connecting to MongoDB Atlas. |
Newer c-ares versions set tcp_port/udp_port to 53 instead of 0, which caused the loopback detection to fail. This fix: - Removes the port check from loopback detection - Adds IPv6 loopback (::1) support - Calls EnsureServers() before each DNS query PR-URL: #61453 Reviewed-By: Anna Henningsen <anna@addaleax.net>
Newer c-ares versions set tcp_port/udp_port to 53 instead of 0, which caused the loopback detection to fail. This fix: - Removes the port check from loopback detection - Adds IPv6 loopback (::1) support - Calls EnsureServers() before each DNS query PR-URL: #61453 Reviewed-By: Anna Henningsen <anna@addaleax.net>
|
Reproduced on Windows 11 with Node v24.14.1 and v24.13.1. Downgrading to v24.11.1 fixed the issue. The error was querySrv ECONNREFUSED when connecting to MongoDB Atlas as well. |
Use github:BabyBear7/helios-core#master until Node 22 LTS backports the c-ares fallback-detection fix (nodejs/node#61453). The fork adds a public-resolver retry path in checkSrv so SRV-only servers no longer appear offline on Node 22 Windows hosts.
|
I still have this issue with Node.js versions:
|
|
same issue still going on with node : 26.3.1 |
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