Developer finds Node.js v22 DNS bug was behind MongoDB Atlas connection failures
A developer building a Node.js and MongoDB Atlas backend repeatedly encountered a 'querySrv ECONNREFUSED' error despite correctly configuring the Atlas cluster, credentials, and IP whitelist. Systematic DNS testing revealed that Node.js was reporting 127.0.0.1 as its DNS server and failing to resolve SRV records, even though Windows itself resolved them correctly. A temporary fix using dns.setServers() with Cloudflare addresses confirmed the issue was DNS-related within Node.js rather than a MongoDB or network misconfiguration. Downgrading from Node.js v22 to v20 LTS fully resolved the problem, restoring normal DNS resolution without any workaround code. The root cause of why Node.js v22 behaved this way on the specific machine remains unclear, though the case highlights the value of isolating and testing individual components during debugging.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in