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 intonodejs:mainfrom
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
|
Getting this same error in version v22.22.0 i am using this to currently work. is there any fix ? require('dns').setServers(['8.8.8.8', '1.1.1.1']); |
Commit Queue failed- Loading data for nodejs/node/pull/61453 ✔ Done loading data for nodejs/node/pull/61453 ----------------------------------- PR info ------------------------------------ Title dns: fix Windows SRV ECONNREFUSED regression by correcting c-ares fallback detection (#61453) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch NotVivek12:main -> nodejs:main Labels c++, cares, author ready, needs-ci Commits 12 - 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 - Merge branch 'nodejs:main' into main - remove the unintentional file Committers 2 - notvivek12 <vivekjoshi82015@gmail.com> - GitHub <noreply@github.com> PR-URL: https://github.com/nodejs/node/pull/61453 Reviewed-By: Anna Henningsen <anna@addaleax.net> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/61453 Reviewed-By: Anna Henningsen <anna@addaleax.net> -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 20 Jan 2026 16:41:51 GMT ✔ Approvals: 1 ✔ - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/61453#pullrequestreview-3736915722 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-02-02T00:50:45Z: https://ci.nodejs.org/job/node-test-pull-request/71159/ - Querying data for job/node-test-pull-request/71159/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 61453 From https://github.com/nodejs/node * branch refs/pull/61453/merge -> FETCH_HEAD ✔ Fetched commits as bdceaa211714..8327d4147038 -------------------------------------------------------------------------------- error: commit 0683f486da242ed3a754b8416b043eafa8a95277 is a merge but no -m option was given. fatal: cherry-pick failed [main de09739b90] fix fix Windows SRV ECONNREFUSED regression Author: notvivek12 <vivekjoshi82015@gmail.com> Date: Tue Jan 20 22:00:39 2026 +0530 1 file changed, 21 insertions(+), 6 deletions(-) ✘ Failed to apply patcheshttps://github.com/nodejs/node/actions/runs/21612134326 |
|
@addaleax What could i do to fix this issue? |
|
please fix this asap! |
…lback detection 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: nodejs#61453 Reviewed-By: Anna Henningsen <anna@addaleax.net>
I've fixed it |
|
Can you explain how to fix that |
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>
|
Landed in 8c32389 (adjusted commit message during merge to make it adhere to our linter rules) |
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