Repository navigation
Description
Summary
On some networks, connecting with a mongodb+srv:// connection string fails before any connection to the server is attempted:
Failed to connect to "<connection name>"
Revisit connection details and try again.
Error: querySrv EBADRESP _mongodb._tcp.<cluster>.global.mongocluster.cosmos.azure.com
On the same machine and network:
nslookup -type=SRV _mongodb._tcp.<host>resolves the record correctly.- Some other tools connect to the same cluster with the same connection string without problems.
- Using a non-SRV
mongodb://host:port,...connection string works. - Switching the machine's DNS server to a public resolver (e.g.
1.1.1.1) works.
The issue was reported by a customer on Windows behind a home router (DNS server 192.168.10.1), both on and off their corporate VPN. It is not Windows-specific: the same failure is a known issue on macOS (see nodejs/node#66173), and it can affect any platform whose DNS resolver behaves the same way (see below).
Root cause
How SRV resolution works in our extension today
We pass the mongodb+srv:// connection string unchanged to the mongodb Node.js driver. To expand an SRV connection string, the driver calls dns.promises.resolve(host, 'SRV') and dns.promises.resolve(host, 'TXT').
In Node.js, every dns.resolve*() call is handled by c-ares, a DNS client library bundled with Node.js. It is not handled by the operating system's resolver. c-ares reads the DNS server list from the OS, sends the query itself, and parses the raw reply bytes itself. (Only dns.lookup(), the A/AAAA lookup used when opening sockets, goes through the OS resolver.)
EBADRESP means c-ares rejected the reply as malformed.
Some other tools are not affected because they resolve SRV records through the OS resolver (e.g. DnsQuery on Windows, res_query on Unix) and only fall back to Node's resolver if that fails. nslookup uses its own, more lenient parser.
The c-ares regression
- c-ares 1.34.7 (released 2026-07-06) included c-ares/c-ares#1190. That change made the reply parser reject DNS name compression in the RDATA of record types outside the original RFC 1035 set, SRV included. With compression, the SRV
TARGEThostname is written as a pointer to a name earlier in the reply instead of in full. - RFC 2782 says servers should not compress SRV targets. However, RFC 3597 §4 explicitly says receivers SHOULD decompress SRV, because older servers still compress it.
- Many DNS forwarders do compress SRV targets: home routers, phone hotspots, Samba AD domain controllers. Public resolvers such as
1.1.1.1and8.8.8.8write the target in full, which is why switching DNS servers works around the issue. - Azure DocumentDB SRV targets (
fc-<id>-000.global.mongocluster.cosmos.azure.com) share a long suffix with the queried name. A compressing forwarder will therefore almost always use a pointer for them.
Node.js picked up c-ares 1.34.7/1.34.8 in v24.19+ and v26.6+. Recent VS Code builds ship this version. I reproduced the failure with the self-contained replay script from nodejs/node#66173, which serves the same SRV answer once with a compressed target and once with the target written in full:
| Runtime | c-ares | Compressed TARGET |
Literal TARGET |
|---|---|---|---|
| Node.js 22.21.1 | 1.34.5 | OK | OK |
| VS Code 1.139.x (Node.js 24.20.0) | 1.34.8 | EBADRESP | OK |
| VS Code 1.140.0 / 1.141.0 (Node.js 24.21.0) | 1.34.8 | EBADRESP | OK |
This explains why users can start seeing the error "suddenly" without any change to their network: VS Code auto-updated to a build that bundles c-ares ≥ 1.34.7.
Upstream status: no fix in sight
- nodejs/node#66173: "dns.resolveSrv returns EBADRESP for all existing SRV records on macOS since v26.6.0 (c-ares 1.34.8)". Open. Root-caused there to c-ares; Node.js has nothing to fix on its side.
- c-ares/c-ares#1287: "SRV replies with compressed TARGET rejected since 1.34.7". Open. The same regression broke SSSD/Samba AD service discovery; Fedora and ALT Linux reverted the change downstream.
- c-ares/c-ares#1290: "Accept compressed SRV/SIG/NAPTR names when parsing responses", the proposed fix. Closed without being merged on 2026-10-05 after a month without review.
Even once a fix lands, it has to ship in a c-ares release, then a Node.js release, then an Electron release, and then a VS Code release before users get it. That is realistically months, so we need our own mitigation.
Related, older issue: nodejs/node#62326. On Windows, Node.js 24.13–24.18 (c-ares 1.34.6) reported 127.0.0.1 as the DNS server, which surfaced as querySrv ECONNREFUSED. That bug was fixed in c-ares 1.34.7, but 1.34.7 is the same release that introduced the SRV parsing regression above. Every c-ares release since 1.34.6 has one of the two bugs: 1.34.6 has the 127.0.0.1 bug on Windows, and 1.34.7/1.34.8 have the SRV parsing regression. Only ≤ 1.34.5 has neither.
Platform exposure
| Platform | DNS server c-ares talks to | Exposure |
|---|---|---|
| Windows | Adapter DNS servers (often the home router) | Exposed |
| macOS | System resolvers (often the router via DHCP); c-ares does not go through macOS's own DNS service (mDNSResponder) | Exposed (nodejs/node#66173) |
| Linux with systemd-resolved | Local stub at 127.0.0.53, which re-serializes replies |
Mostly shielded |
| Linux without a local stub (containers, minimal servers) | Router or upstream server directly | Exposed |
Note: the extension runs where the VS Code extension host runs. Under Remote-SSH, WSL, or Dev Containers, that machine's DNS setup is what matters.
Proposed solution
Add an in-memory, on-the-fly SRV fallback for mongodb+srv:// connection strings, applied immediately before a client is created:
- Primary path (unchanged behavior): resolve SRV/TXT with Node's
dns.promises.resolve*(), exactly as the driver does today. Users who connect successfully today see no change in behavior. - Fallback: only on errors that indicate a broken reply from the DNS server (
EBADRESP; considerEFORMERRandECONNREFUSED), query the same system DNS servers (dns.getServers()) ourselves:- UDP first, then TCP if the reply is truncated (
TCbit set). - Encode and decode messages with
dns-packet: pure JavaScript, MIT, widely used, one small dependency. I verified that it decodes the compressed-target reply that c-ares 1.34.8 rejects (calendar.google.com:443).
- UDP first, then TCP if the reply is truncated (
- Rewrite the URI to
mongodb://host1:port1,host2:port2/...and pass that to the driver. The rewrite must keep the driver's SRV semantics exactly:- Verify that every SRV target is under the parent domain of the original host (the driver's
checkParentDomainMatch). - Apply TXT record options, allowing only
authSource,replicaSetandloadBalanced, and error on multiple or empty TXT records, as the driver does. - Add
tls=trueunless the user explicitly settls/ssl. SRV implies TLS by default. - Remove
srvMaxHostsandsrvServiceName, which are invalid without+srv; honorsrvServiceNameandsrvMaxHostsduring resolution.
- Verify that every SRV target is under the parent domain of the original host (the driver's
- Telemetry/logging: record which path resolved the SRV record (
nodeorfallback) and the original error code. Never log credentials.
Requirement: the resolved connection string is never persisted
The rewrite must be purely in memory and transient:
- It happens on the fly at client-creation time, on every new connection, so changes in the DNS records are always picked up. SRV records here have a 30-second TTL; failover and replica promotion change the targets, and that is the whole point of the
.global.endpoints. - The resolved
mongodb://string must never be written to connection storage, secret storage, settings, the tree/cluster models, or the credential cache. - Every user-facing feature keeps using the original, persisted
mongodb+srv://string: "Copy Connection String", "Update Connection String…", the connection display/edit UI, export, opening a shell, telemetry domain metadata, and so on.
Where it applies
Every place that creates a driver client from a stored connection string should go through the same helper:
src/documentdb/ClustersClient.ts(connect())src/documentdb/connectToClient.tssrc/documentdb/playground/playgroundWorker.ts(runs in a worker; resolve there or in the host before handing over, never persisted)src/services/localQuickStart/QuickStartService.ts(local connections; likely never+srv, but should use the same helper for consistency)
Known gap
If dns.getServers() itself returns the wrong servers (nodejs/node#62326, Node.js 24.13–24.18 on Windows), the fallback would query the wrong server as well. This only affects VS Code builds that bundle c-ares 1.34.6. Current builds (c-ares 1.34.8) no longer have the 127.0.0.1 bug, but they are exactly the builds affected by the SRV parsing regression this issue is about. Only an OS-level resolver would cover the 127.0.0.1 case (see os-dns-native below).
Alternatives considered and rejected
| Alternative | Why rejected |
|---|---|
os-dns-native (native OS resolver: DnsQuery on Windows, res_nquery elsewhere) |
Best results, but it is a native N-API addon that ships no prebuilt binaries ("install": "node-gyp rebuild"). Installing a VSIX never compiles anything, so we would have to build it for every OS and CPU type and ship per-platform VSIXs. Too much packaging risk for a patch release. Could be revisited later as an additional first try ahead of the dns-packet fallback. |
Windows-only Resolve-DnsName fallback |
Does not cover macOS or Linux; requires spawning PowerShell and parsing its output. |
Shelling out to system tools (nslookup / dig / host) |
Parsing tool output is fragile, and the tools are not always installed (minimal Linux, containers). dns-packet does the same job inside our own process. |
Forcing public DNS (Resolver.setServers(['1.1.1.1'])) |
Breaks private endpoints, VPN DNS and corporate split DNS, and sends customers' hostnames to a third-party resolver. |
DNS over HTTPS (e.g. tangerine) |
Same privacy and private-DNS problems as forcing public DNS, plus a large set of dependencies. |
| Retrying the Node.js lookup | The same query to the same server gets the same reply. The driver already retries only on ETIMEOUT. |
| Tuning the c-ares query (disable EDNS, force TCP) | Node.js does not expose these options, and the query is not the problem; the reply parser is. |
| Waiting for the upstream fix | The c-ares fix PR was closed without being merged, and any fix would take months to reach VS Code. |
| Documenting the workaround only | Fine as interim guidance (see below), but a hardcoded host list does not follow failover on .global. endpoints, and changing DNS servers is a machine-wide change. |
Interim workarounds for affected users
- Use a non-SRV connection string. Resolve the SRV record against a public resolver, for example
nslookup -type=SRV _mongodb._tcp.<host> 1.1.1.1, and build:Include every SRV target with its port, keepmongodb://<user>:<password>@<target1>:10260,<target2>:10260/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000tls=true, and add any options from the TXT record (nslookup -type=TXT <host> 1.1.1.1). Caveat: the host list does not follow failover or promotion; re-resolve if the connection stops working. - Change the machine's DNS server to a public resolver (e.g.
1.1.1.1). Caveat: this is machine-wide and may break VPN/corporate name resolution.
How to confirm a user is affected
Run the SRV lookup with VS Code's bundled Node.js runtime, the same resolver the extension uses (Windows cmd):
set ELECTRON_RUN_AS_NODE=1
"%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" -e "require('dns').resolveSrv('_mongodb._tcp.<host>',console.log)" 2>&1 | more
EBADRESP here, while nslookup succeeds, confirms the issue. Close the window afterwards (or run set ELECTRON_RUN_AS_NODE=).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
docs(srv-resolver): explain why the package exists and how to use it
refactor(srv): remove the developer-preview notice