Repository navigation
fix: resolve mongodb+srv:// when Node.js rejects compressed SRV replies (c-ares EBADRESP) - #997
Merged
Tomasz Naumowicz (tnaum-ms) merged 46 commits intoOct 12, 2026
Conversation
The `connectToClient` function is marked as deprecated as it is not used by the extension and is scheduled for removal in a future release. Its only caller, `parseMongoConnectionString`, has no callers in the source code. Users are advised to create clients through `ClustersClient` instead.
M1 of the SRV DNS fallback (#993), work items WI-0 and WI-1: - WI-0: new workspace package packages/documentdb-js-srv-resolver (0.1.0, peer dependency mongodb >=6), linked through npm workspaces, added to the root dependencies, tsconfig references and jest projects. - WI-1: dns-packet ^5.6.1 and @types/dns-packet in the package manifest; freshness check clean (0 fresh). Progress recorded inline in the iteration 01 plan. Co-authored-by: Copilot <[email protected]>
M2 of the SRV DNS fallback (#993), work item WI-2: - srvUriRewrite.ts: rewrite a mongodb+srv:// string plus SRV/TXT records into a mongodb:// string and a sanitized options copy, mirroring the mongodb 7.2.0 resolveSRVRecord semantics (D0004, R3), with userinfo copied verbatim and errors classified through a WeakMap. - Differential tests against the driver's own resolveSRVRecord on the full target list, host selection tested separately (R6). - Shared package constants (D0016 timings) and the cancellation/logger contract (types.ts). Progress recorded inline in the iteration 01 plan (with the M1 SHA). Co-authored-by: Copilot <[email protected]>
M3 of the SRV DNS fallback (#993), work item WI-3: - fallbackDnsClient.ts: dns-packet queries to the dns.getServers() servers in order (D0002, D0003), UDP first and TCP on truncation, reply matching by source, ID, QR and question, Node-shaped error codes, one shared absolute deadline (D0016, R4), caller cancellation, and a raw-bytes probe for compressed SRV targets. - Tests against a local UDP+TCP stub with a hand-built compressed-target reply, TXT "no record" cases (R3) and the shared deadline (R4). - Package index exports the rewrite, the client, constants and types. Progress recorded inline in the iteration 01 plan (with the M2 SHA). Co-authored-by: Copilot <[email protected]>
M4 of the SRV DNS fallback (#993), work item WI-4: - resolveSrvForDriver() in @documentdb-js/srv-resolver: Node probe on a cancellable resolver (D0005, D0017), eligibility (D0012), off/force modes (D0010, D0011), fallback-only driver preflight with a never-invoked OIDC stub (R1), parallel SRV/TXT under one deadline (R4), the rewrite, error rules (original probe error rethrown, validation errors as-is, R5), cancellation that always wins (R2), trace output. - src/documentdb/srv: prepareDriverConnectionString adapter (env switches, connection-timeout cap, output channel at trace, D0014), connect.srvResolution telemetry without hosts or IPs (D0009), startup summary, and the in-memory summary type for the tooltip (WI-10). - launch.json: commented-out switch entries. Progress recorded inline in the iteration 01 plan (with the M3 SHA). Co-authored-by: Copilot <[email protected]>
…ooltip M5 of the SRV DNS fallback (#993), work items WI-5 and WI-10: - WI-5: ClustersClient.initializeClient resolves through prepareDriverConnectionString after connect.staticmetadata; the driver gets the prepared string and options, while credentials, hosts, metadata and the TLS-exception check keep the original string (D0001). connect.startup gets srvResolution and srvResolutionDurationMs. - WI-10: in-memory SrvResolutionSummary per client, read through ClustersClient.getSrvResolution(clusterId) (D0019); one shared tooltip helper applied in buildClusterTooltip, ClusterItemBase and the tree provider choke point; fallback-only row refresh after connecting. Progress recorded inline in the iteration 01 plan (with the M4 SHA). Co-authored-by: Copilot <[email protected]>
M6 of the SRV DNS fallback (#993), work item WI-6: - WorkerSessionManager prepares the connection string on the host before new Worker() (D0008), posts a copy of the init message with the prepared string, the serializable options subset and OIDC allowed hosts computed from the original; the caller's message is untouched. - Per-startup AbortController: kill, dispose and shutdown abort DNS preparation, and no worker is created afterwards (R2). The init timeout starts after preparation (D0018). - The worker prefers the host's oidcAllowedHosts. - PlaygroundEvaluator rethrows the original startup failure, because the telemetry wrapper swallowed UserCancelledError and evaluation could continue after a cancel (coupled R2 fix). Progress recorded inline in the iteration 01 plan (with the M5 SHA). Co-authored-by: Copilot <[email protected]>
M7 of the SRV DNS fallback (#993), work items WI-7 and WI-8: - WI-7: SrvDnsDiagnosticsProvider translates querySrv EBADRESP/EFORMERR/ ECONNREFUSED into neutral, actionable text with a link; it requires SRV evidence, so a plain socket ECONNREFUSED is not matched (R5). Registered last so source-specific providers win. - WI-8: user-manual page troubleshooting-srv-dns.md (symptoms, the ELECTRON_RUN_AS_NODE check, workarounds, timing rule, trace collection, both environment switches incl. Remote/WSL/containers), linked from the index; 0.11.1 changelog and release notes. Progress recorded inline in the iteration 01 plan (with the M6 SHA). Co-authored-by: Copilot <[email protected]>
M8 code review finding C1 (#993, WI-10): withSrvResolutionTooltip copied the tooltip with Object.assign, but VS Code's MarkdownString keeps its value behind prototype accessors over a private field, so a fallback-resolved cluster's tooltip collapsed to the DNS line alone. Copy the fields explicitly, leave already-decorated tooltips unchanged, and test with a MarkdownString double that mirrors VS Code. Adds the M8 code-review triage (code-review.md) and the M7 SHA in the iteration 01 plan. Co-authored-by: Copilot <[email protected]>
M8 of the SRV DNS fallback (#993), WI-9 and hand-over: - WI-9: automated verification summary; manual step 1 run with VS Code's own runtime (Node.js 24.21.0, c-ares 1.34.8: EBADRESP from Node, the fallback decodes the reply); manual steps 2-8 recorded as pending. - Outcome chapter in the iteration 01 plan (commits, verified, not verified, open items). - Feature README: status, code map, code frontmatter, timeline, reading order; feature index status. Co-authored-by: Copilot <[email protected]>
Case 2 verification for the SRV DNS fallback (#993), run after hand-over: - npm run l10n: 5 new strings (diagnostics text, tooltip line). - npm run prettier-fix: formatting of the new package, adapters, tests and feature docs. - npm run lint: 75 errors in this branch's files fixed mechanically (inline type specifiers, no import() type annotations, typed mocks instead of any, explicit null checks); two justified suppressions. - Full jest (302 suites, 4,958 tests), build and package pass. - Plan Outcome records the Case 2 run; the WI-6 note no longer overstates the PlaygroundEvaluator cancellation risk. Co-authored-by: Copilot <[email protected]>
Operator decision after reviewing the WI-10 implementation: the price of the workarounds is too high. Showing the line needs a row redraw after connecting, which refetches the database list, and every way around that (children cache, redraw on disconnect, short-lived reuse flag) adds edge cases to tree code all views share. - Remove srvResolutionTooltip, the change event and the row redraw; the tree files and their tests are back to their v0.11.0 state. - Keep ClustersClient.getSrvResolution(clusterId) and the host-free summary for the future cluster dashboard (FW-2). - Fallback use stays visible in the [SrvResolution] trace and telemetry. - D0021 supersedes D0019; plan, README, future work, user manual, changelog and release notes updated; l10n drops the three strings. Co-authored-by: Copilot <[email protected]>
Operator request for a 0.11.1-preview build (#993): after a successful SRV fallback on a tree connection (ClustersClient), show a non-blocking modal "Developer Preview: DNS workaround applied for <host>" that explains what was detected, that the host names were resolved from the system DNS servers, and that the saved connection string is unchanged. - Once per SRV host per window (notice deduplication only, no DNS caching); never awaited, failures ignored. - "Copy Details" copies runtime and DNS diagnostics without credentials, connection string or resolved target hosts; "Open Troubleshooting Guide" opens the SRV DNS user-manual page. - Gated by SHOW_SRV_FALLBACK_PREVIEW_NOTICE, to be reviewed before the 0.11.1 release (open item in the plan). Co-authored-by: Copilot <[email protected]>
…build Temporary version for the SRV DNS fallback preview VSIX (#993); set to 0.11.1 before the release. Co-authored-by: Copilot <[email protected]>
Tomasz Naumowicz (tnaum-ms)
changed the base branch from
main
to
release/0.11.1
October 12, 2026 05:13
The package README now covers the c-ares regression behind #993 (SRV target compression rejected since c-ares 1.34.7, querySrv EBADRESP), what resolveSrvForDriver() does step by step, a usage example (type-checked against the package API), the options, the lower-level exports, and the guarantees and limits (transient string, no SRV polling on the fallback path, same DNS servers, driver-parity tests). Co-authored-by: Copilot <[email protected]>
Operator decision (#993): the experimental phase with the 0.11.1-preview build (72d3d01) has completed. Remove the modal shown after a successful fallback on a tree connection, its tests, its call site in prepareDriverConnectionString and its 30 localized strings. src/documentdb/srv is back to its 3024e37 state; fallback use stays visible in the [SrvResolution] trace and in telemetry (D0021). Plan and feature README updated; the remaining release item is setting the version from 0.11.1-preview to 0.11.1. Co-authored-by: Copilot <[email protected]>
Drop the SRV target compression scanner and its telemetry flag, the per-attempt records and reply byte counts (trace already logs each attempt), the test-only parseDnsServers export, the package marker constant and the timer re-arming. Trim the DNS client tests to the behaviour that matters.
Keep only what the driver's SRV resolution adds or rejects: the host list, the parent-domain check, the TXT option allowlist, implicit TLS and dropping srvServiceName/srvMaxHosts. Option conflicts are left to the driver when it parses the rewritten string. srvMaxHosts takes the first N targets. Rewrite errors carry their kind on SrvRewriteError instead of a WeakMap, and never include the connection string. Trim the unit and differential tests to the cases that still apply.
…iver The throwaway MongoClient preflight (and its OIDC callback stub) only made invalid options fail with the driver's message before the fallback ran; the real client still rejects them after the rewrite. resolveSrvForDriver now builds one mutable report, relies on the probe resolver's cancel() and the DNS client's own abort handling instead of a Promise.race wrapper and per-step cancellation checks, classifies fallback errors by type (SrvRewriteError, FallbackDnsError syscall) instead of tracking stage and identity, and drops the test-only input hooks. Tests mock node:dns and the DNS client instead. The worker passes only the OIDC mechanism to preparation, so a TXT authSource is not applied to Entra ID connections.
…ConnectionString Run the resolution directly and send the connect.srvResolution event afterwards from the report. This removes the linked AbortController, the held original failure, the sanitized stand-in error and the post-wrapper rethrow that existed only because the wrapper swallows cancellations. The event keeps its Succeeded/Failed/Canceled result.
…lper Telemetry keeps the path, codes, transport, TXT source, DNS server class, runtime versions, Azure endpoint flag and timings. Drop txtOptionsApplied, tlsAdded, isGlobalEndpoint and dnsServerIpFamily, and the report fields that only fed them. The worker reads the host-computed OIDC allowed hosts inline instead of through a one-line module.
Keep one test per behaviour: diagnostics translation, ClustersClient handing the transient string to the driver while metadata, credentials and the TLS exception use the original, and the worker startup paths (serializable options, cancellation during DNS, stale startup, failure, timeout start, OIDC). Drop the surface-by-method and per-path matrices.
Remove the tooltip flag (D0019, WI-10, review finding C1), the superseded D0006, the developer-preview notice, the driver preflight (design review R1) and the compression and telemetry fields that no longer exist. D0021 and D0022 now state the current decisions and their rejected alternatives instead of the history.
The package used mongodb only for the MongoClientOptions type. Options are now any object, read through a small structural SrvClientOptions type, and the caller's own options type is returned. mongodb stays as a dev dependency for the differential test against the driver.
Tomasz Naumowicz (tnaum-ms)
marked this pull request as ready for review
October 12, 2026 07:41
Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Webview diagnostics, case-insensitive DNS validation, and forced fallback behavior have unresolved defects.
3 open findings
What changed in this PR
Adds an in-memory SRV DNS fallback for Node.js/c-ares failures affecting mongodb+srv:// connections.
Changes:
- Introduces reusable UDP/TCP SRV resolution and URI rewriting.
- Integrates fallback, cancellation, diagnostics, and telemetry across connection surfaces.
- Adds publishing, release, troubleshooting, and design documentation.
Case 2 applies; automated checks are reported as passing, while manual validation remains pending.
| File | Description |
|---|---|
tsconfig.json |
References the resolver workspace. |
src/documentdb/srv/srvResolutionTelemetry.ts |
Maps resolution reports to telemetry. |
src/documentdb/srv/srvResolutionTelemetry.test.ts |
Tests telemetry privacy and classification. |
src/documentdb/srv/srvResolutionSummary.ts |
Defines in-memory resolution summaries. |
src/documentdb/srv/SrvDnsDiagnosticsProvider.ts |
Adds SRV failure explanations. |
src/documentdb/srv/SrvDnsDiagnosticsProvider.test.ts |
Tests diagnostic matching. |
src/documentdb/srv/prepareDriverConnectionString.ts |
Adapts resolver behavior for the extension. |
src/documentdb/srv/prepareDriverConnectionString.test.ts |
Tests adapter behavior and telemetry. |
src/documentdb/playground/workerTypes.ts |
Passes host-derived OIDC allowlists. |
src/documentdb/playground/WorkerSessionManager.ts |
Resolves SRV before worker startup. |
src/documentdb/playground/WorkerSessionManager.test.ts |
Tests cancellation and worker integration. |
src/documentdb/playground/playgroundWorker.ts |
Consumes the supplied OIDC allowlist. |
src/documentdb/playground/PlaygroundEvaluator.ts |
Preserves original startup errors. |
src/documentdb/connectToClient.ts |
Documents fallback exclusion for deprecated code. |
src/documentdb/ClustersExtension.ts |
Registers SRV diagnostics. |
src/documentdb/ClustersClient.ts |
Prepares transient driver connection strings. |
src/documentdb/ClustersClient.test.ts |
Tests transient URI handling. |
src/constants.ts |
Adds the troubleshooting link. |
packages/documentdb-js-srv-resolver/tsconfig.json |
Configures the ESM package build. |
packages/documentdb-js-srv-resolver/src/types.ts |
Defines logging and cancellation contracts. |
packages/documentdb-js-srv-resolver/src/test/dnsStubServer.ts |
Provides UDP/TCP DNS test infrastructure. |
packages/documentdb-js-srv-resolver/src/srvUriRewrite.ts |
Rewrites SRV URIs for the driver. |
packages/documentdb-js-srv-resolver/src/srvUriRewrite.test.ts |
Tests rewrite semantics. |
packages/documentdb-js-srv-resolver/src/srvUriRewrite.differential.test.ts |
Compares behavior with the driver. |
packages/documentdb-js-srv-resolver/src/resolveSrvForDriver.ts |
Selects native or fallback resolution. |
packages/documentdb-js-srv-resolver/src/resolveSrvForDriver.test.ts |
Tests path selection and cancellation. |
packages/documentdb-js-srv-resolver/src/report.ts |
Defines observability reports. |
packages/documentdb-js-srv-resolver/src/index.ts |
Exports the package API. |
packages/documentdb-js-srv-resolver/src/fallbackDnsClient.ts |
Implements UDP/TCP DNS queries. |
packages/documentdb-js-srv-resolver/src/fallbackDnsClient.test.ts |
Tests DNS transport behavior. |
packages/documentdb-js-srv-resolver/src/constants.ts |
Defines fallback deadlines. |
packages/documentdb-js-srv-resolver/README.md |
Documents package usage and limits. |
packages/documentdb-js-srv-resolver/package.json |
Defines the publishable package. |
packages/documentdb-js-srv-resolver/LICENSE.md |
Adds package licensing. |
packages/documentdb-js-srv-resolver/jest.config.cjs |
Configures package tests. |
package.json |
Adds the workspace dependency and patch version. |
package-lock.json |
Locks the workspace and DNS dependency. |
l10n/bundle.l10n.json |
Adds localized diagnostic strings. |
jest.config.js |
Includes the ESM package in Jest. |
docs/user-manual/troubleshooting-srv-dns.md |
Adds SRV troubleshooting guidance. |
docs/user-manual/how-to-construct-url.md |
Links SRV troubleshooting. |
docs/release-notes/0.11.md |
Adds 0.11.1 release notes. |
docs/index.md |
Indexes the new documentation. |
docs/ai-and-plans/README.md |
Registers the feature documentation. |
docs/ai-and-plans/features/srv-dns-fallback/README.md |
Summarizes the feature design. |
docs/ai-and-plans/features/srv-dns-fallback/iterations/01-srv-fallback/design-review.md |
Records design findings. |
docs/ai-and-plans/features/srv-dns-fallback/iterations/01-srv-fallback/code-review.md |
Records the prior review. |
docs/ai-and-plans/features/srv-dns-fallback/future-work.md |
Tracks deferred improvements. |
docs/ai-and-plans/features/srv-dns-fallback/decisions.md |
Records implementation decisions. |
CHANGELOG.md |
Adds the 0.11.1 fix entry. |
.vscode/launch.json |
Documents debug environment switches. |
.github/workflows/npm-publish-documentdb-js.yml |
Enables resolver package publishing. |
.azure-pipelines/compliance/CredScanSuppressions.json |
Suppresses test-only fake credentials. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use three IDs: startupCorrelationId (one per database client, kept for its lifetime), connectionCorrelationId (link to the extension client's cluster metadata) and the shell/playground session IDs. - Log lines about a connection carry startup=<id>; SRV logs never fall back to a metadata link or session ID. - Workers tie logs, exit/error lines and token requests to the startup ID of the worker that sent them. - Auth traces show the connection's startup ID, or authId=<id> outside a connection. Managed-identity failure events link to the startup. - connect.startup and the metadata events add startupCorrelationId. - Rewrite the correlation-ID doc to the simple model.
A killed or replaced worker exits asynchronously. Its exit handler could fire while the next worker was starting, marking the new startup as exited, rejecting its init request and clearing the new worker. Only the current worker can now exit unexpectedly; terminateWorker() detaches a worker before it exits, which replaces the shared _terminatingIntentionally flag.
The auth trace strings changed, so the l10n bundle is regenerated. The ClustersClient test narrowed a telemetry value before interpolating it.
Accept qualifying querySrv messages that cross the webview boundary as plain strings while preserving existing Error handling. Refs: PR #997 review C1
…s fast Use a connected UDP socket so the kernel reports refused DNS peers immediately instead of waiting for the attempt timeout. Refs: PR #997 review P1
Retry only servers whose first attempt timed out while keeping the shared deadline and distinct server count unchanged. Refs: PR #997 review P4
Record the caller invariant while SRV preparation runs before the worker reference is assigned. Refs: PR #997 review P5
The code and plan WI-4 (R5) run the probe before a forced fallback, so forced events keep nodeErrorCode and nodeProbeDurationMs. Align the decision text with that instead of skipping the probe. Refs: PR #997 review C2
srvMaxHosts is removed before the driver parses the rewritten string, so its replicaSet and loadBalanced conflicts are not rejected on the fallback path. The decision said all option conflicts are left to the driver. Refs: PR #997 review P6
…r merge D0023 replaced the D0020 'not published' position. Refs: PR #997 review P8
…-ares-workaround # Conflicts: # docs/ai-and-plans/README.md
Contributor
✅ Code Quality Checks
This comment is updated automatically on each push. |
Contributor
📦 Build Size Report
Download artifact · updated automatically on each push. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #993
What changed
mongodb+srv://connections work again on networks whose DNS servers compress the SRV target (many home routers, phone hotspots, some VPN and corporate DNS servers, Samba AD). Since c-ares 1.34.7, which recent VS Code builds ship, Node.js rejects those valid replies withquerySrv EBADRESPbefore any connection is attempted.When Node.js's own SRV lookup fails with
EBADRESP,EFORMERRorECONNREFUSED, the extension now resolves the SRV and TXT records itself withdns-packet(UDP, then TCP), asking only the system's own DNS servers (dns.getServers()), and hands the driver an equivalentmongodb://host1,host2/...string. That string exists only in memory for that one connection; saved connections, Copy Connection String and exports keep the originalmongodb+srv://string.ClustersClient), and the interactive shell and query playground (resolved on the host before the worker starts, D0008).+srvstring and keeps its own SRV polling.tls=true,srvMaxHosts,srvServiceNameand the$externalrule forauthSource. A differential test compares the rewrite with the installed driver's own SRV resolution.querySrv EBADRESP/EFORMERR/ECONNREFUSEDinto an actionable message that links to the new SRV DNS troubleshooting page.DOCUMENTDB_DISABLE_SRV_FALLBACK=1(documented). No user setting (D0011).connect.srvResolutiontelemetry event per+srvconnection (path, error codes, transport, timings; no hosts or IPs), and[SrvResolution]lines in the output channel at Trace level.0.11.1release notes and changelog entry. The branch targetsrelease/0.11.1and is forward-merged intomainafterwards (D0015).New package:
@documentdb-js/srv-resolverThe VS Code-independent logic (URI rewrite, fallback DNS client, resolve function) lives in a new workspace package so other MongoDB API tools can reuse it (D0020). It has one dependency (
dns-packet) and no dependency on the driver. It ships ESM-only as1.0.0, following Stage 3 of the modernization plan in #880, so the first published version does not need a breaking switch later (D0023). Thenpm-publish-documentdb-js.ymlworkflow has a newpublish_srv_resolverinput; publishing happens after this PR merges.While this branch still runs Jest, two bridges are needed and go away with Vitest: the package's tests use ts-jest with a CommonJS override (SWC breaks
jest.spyOnonnode:dns), and the rootjest.config.jscompiles the package's ESMdistto CommonJS.Why this shape
srvMaxHoststakes the first N targets instead of the driver's random sample.Scope (not in this PR)
dns.getServers()(the c-ares 1.34.6 Windows bug) is not handled (FW-3).QuickStartServiceand the deprecatedconnectToClient(D0007).Validation
Automated (Case 2, on
8d629ccb):npm run l10n,prettier-fix(format-only commit38ef8e35),lint(0 errors),build,package(vscode-documentdb-0.11.1-preview.vsix, 9.17 MB)npx jest: 298 suites, 4,673 tests, 4 snapshots, all passingrequire()andimport. A CommonJS webpack bundle of the package resolved SRV against a local UDP DNS stub.resolveSrvfails withEBADRESPon a compressed-target reply that the fallback client decodes.Needs a human (plan WI-9, manual steps 2 to 8, not yet run):
DOCUMENTDB_DEBUG_FORCE_SRV_FALLBACK=1) against a.global.cluster with native auth and Entra ID: tree, Collection View, interactive shell and playground.path=fallback,nodeErrorCode=EBADRESP.mongodb+srv://.path=node, and check thenodeProbeDurationMsoverhead.tc ... netem delay 3000ms): the fallback still succeeds within the D0016 limits.AI pre-review: code-review.md (M8, at
cbd711d6). The simplification pass (D0022) and the package's ESM conversion (D0023) were committed after that review.Links
docs/ai-and-plans/features/srv-dns-fallback/: decisions, plan, design review, code review