Skip to content

Invert the DnsClient transport contract and split resolver settings out - #9122

Merged
fubhy merged 3 commits into
feat/net-dns-over-httpsfrom
feat/net-dns-client-api
Oct 14, 2026
Merged

fubhy merged 3 commits into
feat/net-dns-over-httpsfrom
feat/net-dns-client-api

Conversation

@tim-smart

Copy link
Copy Markdown
Contributor

Stacked on #8962 (feat/net-dns-over-https). Implements the API changes agreed in the design review of that PR.

  • Transport.servers[].send now returns Effect<Reply, DnsError, Scope>, with Reply = { bytes, age? }. The client closes the scope and applies its timeout around every send, so transports can no longer skip them. Exchange is reduced to encode, matches, and fail. A UDP to TCP retry shares one timeout budget per server attempt, which is what the MakeOptions doc already described.
  • The DNS over HTTPS transport reports the HTTP Age header as Reply.age, and the client subtracts it from resource record TTLs, floored at zero (RFC 8484 §5.1). OPT metadata and SOA timers are untouched.
  • DnsClient is now { query }. search, ndots, noAaaa, and hosts move to DnsClient.layerDns(options?).
  • NodeDnsClient.layerDns(options?) builds the transport, client, and Dns from the single Options object and provides Dns.Dns | DnsClient.DnsClient. Its doc contrasts it with NodeDns.layer.
  • NodeDnsClient defaults nameServers to dns.getServers(), deduplicated and without scoped IPv6 addresses, falling back to loopback when there are none.
  • Exchange.encode defaults udpPayloadSize to 1232 bytes, and the TransportHttpsOptions doc states that non-fetch clients do not follow redirects.

Existing tests are updated to the new API; the Node integration suites now go through NodeDnsClient.layerDns. No test covers the Age subtraction yet.

Closes EFF-2076

@changeset-bot

changeset-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: a9f1647

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

- `Transport.send` returns a `Reply` in a scope; the client closes the scope
  and applies its timeout, so a UDP to TCP retry shares one budget
- Subtract the HTTP `Age` header from resource record TTLs (RFC 8484 §5.1)
- Move `search`, `ndots`, `noAaaa`, and `hosts` from `DnsClient` to
  `layerDns(options)`
- Add `NodeDnsClient.layerDns`, providing `Dns` and `DnsClient` from one
  options object, and default name servers to `dns.getServers()`
- Make `Exchange.encode` default `udpPayloadSize` to 1232 bytes
@tim-smart
tim-smart force-pushed the feat/net-dns-client-api branch from bd6cb83 to 522d855 Compare October 13, 2026 21:31
const systemNameServers = (): ReadonlyArray<NetAddress.InetAddress> => {
let servers: ReadonlyArray<string>
try {
servers = NodeDnsApi.getServers()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! Bad clanker!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 795fb8b: the read is an Effect.sync now, with no try/catch, and explicit nameServers skip it.

@tim-smart

tim-smart commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Rationale for the changes in this PR, since the description only lists them.

Why send returns Effect<Reply, DnsError, Scope> and Exchange.limit is gone. In the base, the client handed every transport a bundle of callbacks and trusted it to wrap its work in limit to get the scope, the timeout, and the error mapping. A custom transport that forgets limit is an unbounded query with leaked sockets, and nothing in the types says so. Now the client owns Effect.scoped and the timeout around every send, and the DnsError error channel forces transports to map socket errors through exchange.fail instead of leaking them. It also fixes a doc mismatch: MakeOptions said the timeout covered an exchange "including a retry over TCP", but each limit call had its own timeout, so a UDP to TCP retry got two budgets. It now gets one per server attempt, which is what the doc promised.

Why Reply carries age. RFC 8484 §5.1 says a DoH client must subtract the HTTP Age from TTLs. Doing that inside the DoH transport means patching TTL bytes in the wire message, which needs a parser the transport should not have. And it is not DoH-specific: a caching transport needs the same field. Reporting age and letting the client subtract it from the decoded TTLs keeps the subtraction in one place. Only resource record TTLs are touched, floored at zero. OPT and the SOA timers are not TTLs and are left alone. Adding age later would change the return type of every custom transport, so it goes in with the contract change. It is named Reply rather than Response because DnsClient.Response already means the decoded message.

Why DnsClient is { query }. search, ndots, noAaaa, and hosts were only ever read by layerDns. A wire client should not carry a hosts table. They moved to DnsClient.layerDns(options?), which is a function now rather than later, before anyone writes a transport against the old shape.

Why NodeDnsClient.layerDns(options?) exists. The split above would make Node users spread parseResolvConf twice, once into the client and once into layerDns. NodeDnsClient.Options already covers both halves, so one call builds the transport, client, and Dns. It provides Dns.Dns | DnsClient.DnsClient so someone who starts with lookup can reach the wire client for TTLs or authority without rebuilding the stack. Its doc says when to pick it over NodeDns.layer, since both provide Dns.Dns from a Node package and the difference (your name servers over sockets vs. the OS resolver with hosts file, mDNS, and so on) was not written down anywhere.

The dns.getServers() default, and the review comment. The motivation was that NodeDnsClient.layerDns() with no options times out silently on macOS and on any systemd-resolved box, because the loopback default queries 127.0.0.1:53. dns.getServers() is the one portable source of the system's name servers (it covers Windows, where there is no resolv.conf) and it is available on all three runtimes, so it stays the default. The review comment was about how it was read, not whether: a plain function with a try/catch and a [] fallback. 795fb8b replaces that with an Effect.sync, so the read happens when the client is built, and drops the catch, since none of the runtimes throws from getServers(). Explicit nameServers skip the read. The dedupe stays because Deno reports each server twice, and scoped IPv6 addresses are still dropped because the client cannot use them.

Smaller items. Exchange.encode takes an optional udpPayloadSize because for TCP and HTTPS it is only the EDNS buffer size, and requiring it there was noise. The TransportHttpsOptions doc now says non-fetch clients do not follow redirects, because redirect: "manual" is set through FetchHttpClient.RequestInit and a NodeHttpClient user had no way to know they were already covered (undici and node:http do not follow redirects, and a 3xx fails as InvalidResponse).

Validation policy stays as it was (core make throws, the platform modules clamp), and a layerSystem that reads /etc/resolv.conf and /etc/hosts is out of scope here.

Replace the try/catch around dns.getServers() with an Effect.sync, so the
read happens when NodeDnsClient runs rather than in a plain function, and
drop the catch: none of the runtimes throws from getServers(). Explicit
nameServers still skip the read.
@fubhy
fubhy merged commit fec7d30 into feat/net-dns-over-https Oct 14, 2026
@fubhy
fubhy deleted the feat/net-dns-client-api branch October 14, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants