Skip to content

perf_hooks: emit 'dns' observer entries, stop advertising 'resource' - #33041

Closed
robobun wants to merge 8 commits into
mainfrom
farm/d3a26afa/perf-observer-dns-resource
Closed

robobun wants to merge 8 commits into
mainfrom
farm/d3a26afa/perf-observer-dns-resource

Conversation

@robobun

@robobun robobun commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

PerformanceObserver.supportedEntryTypes advertises dns and resource, and observe() accepts them, but neither type is ever delivered. That is the worst outcome for feature detection, which is the one job supportedEntryTypes has: code checks the list, sees support, registers an observer, and silently collects nothing.

const seen = [];
new PerformanceObserver(l => l.getEntries().forEach(e => seen.push(`${e.entryType}:${e.name}`)))
  .observe({ entryTypes: ["dns", "resource"] });
await require("node:dns").promises.lookup("localhost");
// Node: ["dns:lookup"]
// Bun:  []

dns: deliver the entries

node:net and node:http already record their net and http entries through internal/shared's hasObserver/startPerf/stopPerf, but node:dns never called into it, so dns was advertised (it is in kNodeEntryTypes) with no producer.

This wires every node:dns operation into that machinery: lookup, lookupService, every resolve*, resolve(hostname, rrtype), and reverse, across the callback API, the promises API, and Resolver / promises.Resolver instances. Three small helpers wrap the native promise so each call site stays a single expression and costs nothing when no dns observer is registered. Semantics match Node (lib/dns.js, lib/internal/dns/{promises,callback_resolver}.js):

  • an entry is recorded only when the operation was dispatched and completed successfully; failures and the IP-literal / empty-hostname early returns in lookup record nothing
  • entries are named after the c-ares binding Node uses: lookup, lookupService, queryA, queryAaaa, queryTxt, ..., getHostByAddr for reverse
  • detail carries the same fields Node records ({hostname, family, hints, verbatim, order, addresses} for lookup, {host, port, hostname, service} for lookupService, {host, ttl, result} for resolvers)

Since node:net resolves hostnames through dns.lookup, net.connect("example.com", ...) now also produces a dns:lookup entry, as it does in Node.

Most of the dns.ts diff is Prettier re-indenting the call sites it touches; reviewing with whitespace hidden shows the real change.

resource: stop advertising it

Nothing in Bun can produce a resource entry. Performance::addResourceTiming has zero callers, performance.markResourceTiming is a no-op stub, and the HTTP client collects no per-request timing for fetch() to report. Per the Performance Timeline spec, supportedEntryTypes lists the types for which an entry could exist in the global, so resource is removed. This is a one-line hunk, independent of the dns change, and should be reverted by whichever change implements resource timing.

Actually implementing resource timing is a separate feature, not a one-liner: the PerformanceResourceTiming consumer side in WebCore is real and compiled, but the producer side needs new per-phase instrumentation in the HTTP client's connection callbacks, plumbing through HTTPClientResult, and a conversion into the synthetic clock domain Performance::m_timeOrigin uses. Happy to write that up as a tracking issue.

Verification

New tests, both failing without the fix:

  • test/js/node/perf_hooks/perf_hooks.test.ts
    • asserts the exact supportedEntryTypes lists for the web global (["mark", "measure"]) and for node:perf_hooks (["dns", "http", "mark", "measure", "net"])
    • spawns dns-entries-fixture.ts, which runs a local UDP DNS responder and points dns.setServers() at it in its own process, so all twelve expected entries (covering every structurally distinct call-site shape) are produced hermetically and in a deterministic order, with exact detail values. Also covers the negatives: an IP-literal lookup, an NXDOMAIN, and an operation after disconnect() record nothing.
  • test/js/node/test/parallel/test-dns-perf_hooks.js: Node's own test for this, ported verbatim from nodejs/node. Previously failed with 0 !== 4; now exits 0.

Existing test-net-perf_hooks.js, test-http-perf_hooks.js, the performance observer leak test, and the node:dns suites are unaffected (bun bd test test/js/node/dns/ test/js/bun/dns/ reports the same set of failures as stock, all of which need direct network access).

Reported by bun-sys-fuzz.

PerformanceObserver.supportedEntryTypes advertised two entry types that
could never be delivered, which defeats the feature detection the list
exists for: code sees support, calls observe(), and collects nothing.

'dns': node:dns never recorded the entries that node:net and node:http
already record through internal/shared's hasObserver/startPerf/stopPerf.
Record one for every lookup/lookupService/resolve*/reverse that completes
successfully, across the callback API, the promises API, and Resolver
instances, using the entry names and detail fields Node uses.

'resource': nothing in Bun calls Performance::addResourceTiming, so no
resource entry can exist. Remove it from supportedEntryTypes so feature
detection reflects reality.
@robobun

robobun commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 2:47 AM PT - Jun 29th, 2026

❌ @robobun, your commit a7a3b15 has 1 failures in Build #66684 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 33041

That installs a local version of the PR into your bun-33041 executable, so you can run:

bun-33041 --bun

Comment thread src/js/node/dns.ts Resolved
Comment thread src/js/node/dns.ts Resolved
Two review findings:

detail.result for A/AAAA queries recorded the raw native [{address, ttl}]
array instead of the value the caller receives, which is what Node records.
Move the existing promisifyResolveX normalization into the promise that
observeQuery wraps, which also replaces the duplicated ttl ternaries in the
resolve4/resolve6 callback bodies with that helper. Verified the
caller-visible results of every restructured path are byte-identical.

observeLookup recorded an entry for a lookup that fulfills with no
addresses, even though the caller sees that as ENODATA (throwIfEmpty).
Skip it, matching "failed lookups record nothing".

The fixture gains a resolve4 {ttl: true} call and the test now asserts the
exact detail.result values for both ttl states and for a TXT query.
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7571c199-a3c5-4955-a433-6df364ab9b77

📥 Commits

Reviewing files that changed from the base of the PR and between 8599a6c and 14067c9.

📒 Files selected for processing (2)
  • src/js/node/dns.ts
  • test/js/node/perf_hooks/dns-entries-fixture.ts

Walkthrough

DNS APIs now emit "dns" performance entries through new observation helpers. supportedEntryTypes drops "resource", and new fixture and tests validate entry delivery and detail shapes.

Changes

DNS perf_hooks instrumentation

Layer / File(s) Summary
Observer helpers and imports
src/js/node/dns.ts
Imports perf utilities, adds the DNS perf entry helper wrappers, and reuses shared lookup result ordering.
Callback DNS instrumentation
src/js/node/dns.ts
Wraps callback lookup, lookupService, and Resolver query methods with perf observation while preserving result shaping and translated error handling.
Promise DNS instrumentation
src/js/node/dns.ts
Wraps promises.lookup, promises.lookupService, promises.resolve*, promises.reverse, and class-based Resolver promise methods with perf observation.
Supported entry types
src/jsc/bindings/webcore/PerformanceObserver.cpp
PerformanceObserver::supportedEntryTypes now returns only "mark" and "measure" and no longer includes "resource".
Fixture and test coverage
test/js/node/perf_hooks/dns-entries-fixture.ts, test/js/node/perf_hooks/perf_hooks.test.ts, test/js/node/test/parallel/test-dns-perf_hooks.js
Adds a DNS fixture and tests that collect and validate "dns" performance entries.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: DNS perf entries plus removal of resource advertising.
Description check ✅ Passed The description covers the change and verification well, though the headings don't exactly match the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/js/node/dns.ts`:
- Around line 281-292: The lookup perf entry is capturing ordering metadata and
addresses before they match the actual lookup result. Update the logic in dns.ts
around the lookup/lookupPromise path so the perf detail uses the real ordering
mode when setting verbatim, and make sure the addresses passed to stopPerf are
recorded after the same ipv4first/ipv6first reordering used by lookup() and
promisifyLookup*(). Keep the fix localized to the lookup perf detail
construction and the final result mapping so the emitted dns entry reflects the
true address order.

In `@test/js/node/perf_hooks/dns-entries-fixture.ts`:
- Around line 57-63: The fixture in the dns perf hooks test is still using
OS-backed resolution through dns.lookup and dns.lookupService, so it is not
hermetic. Update the dns-entries fixture to rely only on dns.resolve* or a
Resolver instance that is actually served by the local UDP server, or make the
lookup/lookupService steps optional and adjust the parent assertion to match the
emitted entries. Keep the ordering logic in dns-entries-fixture.ts and the
corresponding perf_hooks assertion in sync so the test no longer depends on host
resolver configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 92641ba8-979b-4be0-b8a6-1950af3aaf2e

📥 Commits

Reviewing files that changed from the base of the PR and between f789198 and 76e08ce.

📒 Files selected for processing (5)
  • src/js/node/dns.ts
  • src/jsc/bindings/webcore/PerformanceObserver.cpp
  • test/js/node/perf_hooks/dns-entries-fixture.ts
  • test/js/node/perf_hooks/perf_hooks.test.ts
  • test/js/node/test/parallel/test-dns-perf_hooks.js

Comment thread src/js/node/dns.ts Resolved
The lookup entry's detail.verbatim was derived as order !== "ipv4first",
which reports true for "ipv6first"; Node reports order === "verbatim"
(lib/dns.js: verbatim: order === DNS_ORDER_VERBATIM). detail.addresses was
also recorded before the requested order was applied, while Node's resolver
hands them back already ordered.

Extract the result ordering that the three lookup consumers each wrote out
inline into sortByOrder() and apply it to the recorded addresses too;
re-applying it downstream is a no-op. The fixture now requests an explicit
non-default order and the test asserts that entry's exact detail.
Comment thread src/js/node/dns.ts Resolved
… sees it

The lookup entry's detail.addresses was always the plain address strings.
For {all: true} Node's onlookupall records the same [{address, family}]
array it hands to the caller (lib/dns.js builds the objects in place before
calling stopPerf), so record the caller-visible shape for both modes. The
fixture gains an {all: true} lookup and the test asserts the element shape
of both.
Comment thread src/js/node/dns.ts Resolved
robobun added 2 commits June 29, 2026 06:04
getnameinfo("127.0.0.1") fails with ENOTFOUND on the Windows CI runners:
Windows ships its hosts file without a 127.0.0.1 entry, so c-ares falls
through to a PTR query against the configured server, and the fixture's
server did not answer PTR. Reverse 192.0.2.1 (TEST-NET-1, in nobody's hosts
file) instead and answer the PTR query from the local server, so every
platform resolves it the same hermetic way. Verified on Linux, which now
takes the identical PTR-to-local-server path Windows does.
…tches

promises.Resolver.prototype.resolve coerces a non-string rrtype to null (a pre-existing divergence from Node and from the other two resolve variants, which throw). The native resolver treats null as an A query, so the recorded entry said "queryNull" for a query that was really an A lookup.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/js/node/perf_hooks/dns-entries-fixture.ts`:
- Around line 2-5: The opening comment in dns-entries-fixture should be folded
to fit the repo’s 3-line comment limit. Update the top-of-file comment near the
fixture setup so it conveys the same purpose using at most three lines, keeping
the references to the UDP DNS server, the parent perf_hooks test, and
dns.setServers() but shortening or combining the wording.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7540db91-4c91-482b-aefd-bc830fd4e600

📥 Commits

Reviewing files that changed from the base of the PR and between 76e08ce and 8599a6c.

📒 Files selected for processing (3)
  • src/js/node/dns.ts
  • test/js/node/perf_hooks/dns-entries-fixture.ts
  • test/js/node/perf_hooks/perf_hooks.test.ts

@robobun

robobun commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

For a maintainer looking at the red check: every CI failure on this PR is infrastructure or a known-flaky test unrelated to this change. No job that has run the new tests has failed since ebf3278.

Across the last two builds (66676 and 66684, the second an empty retrigger), the failures are:

  • darwin 26 aarch64 - test-bun, on three different agents, each dying before a single test runs:

    Error: buildkite-agent artifact download timed out after 120s for step 'darwin-aarch64-build-bun'. Refusing to continue with a partial download (would silently fall back to the wrong binary).
    

    The same job is failing the same way on unrelated PR builds (66666, 66669, 66673), so the macOS 26 arm64 runners' artifact downloads are down fleet-wide at the moment. That lane needs a retry once they recover.

  • both alpine x64 lanes on 66684: test/js/node/test/parallel/test-net-connect-memleak.js, a GC collection assertion that is already being quarantined on exactly this platform in Quarantine test-net-connect-memleak on linux-x64-musl #33045. This PR does not touch node:net, and the node:dns instrumentation it adds returns the native promise untouched when no dns observer is registered, which is the case in that test.

Everything else is green, including the two Windows lanes whose earlier failure was real and was fixed in ebf3278 (getnameinfo("127.0.0.1") has no hosts entry to use on Windows, so the fixture now reverses a TEST-NET address through its own local DNS server on every platform). All review threads are resolved. I pushed one retrigger for the infra lane and will not push more.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All the inline issues I raised have been addressed and the latest pass found nothing new, but this restructures every node:dns call site (callback, promises, and both Resolver classes) and drops "resource" from the web-global supportedEntryTypes, so it's worth a human sanity-check before merge.

Extended reasoning...

Overview

This PR does two things: (1) wires every node:dns operation — lookup, lookupService, every resolve*/reverse, across the callback API, dns.promises, and both Resolver classes — through three new observeLookup/observeLookupService/observeQuery helpers so a PerformanceObserver({entryTypes:['dns']}) actually receives entries, and (2) removes "resource" from the WebCore PerformanceObserver.supportedEntryTypes list since nothing in Bun produces resource-timing entries. It also extracts a sortByOrder() helper that the three pre-existing lookup consumers now share. Tests: a hermetic fixture with a local UDP DNS responder asserting the exact 12-entry list and detail shapes, a supportedEntryTypes assertion, and Node's vendored test-dns-perf_hooks.js.

Security risks

None identified. The instrumentation is observe-only (it reads results already destined for the caller and reports them to a PerformanceObserver), gated on hasObserver('dns') so it's a no-op when nothing subscribes. No new inputs are parsed, no auth/crypto/permissions surfaces are touched, and the C++ change only removes a string from a static list.

Level of scrutiny

Medium-high. src/js/node/dns.ts is a core Node-compat module on the path of every DNS resolution; the diff restructures ~30 call sites (most of the visual churn is Prettier re-indentation, but each call now flows through a wrapper and several A/AAAA paths moved their promisifyResolveX transform inside the wrapped promise). Over three review rounds, five real detail-shape/semantics issues were found and fixed (empty-result entries, A/AAAA detail.result shape, verbatim for ipv6first, {all:true} detail.addresses shape, queryNameFor(null)), plus a Windows hermeticity fix for lookupService in the test fixture. All are now resolved and covered by tightened assertions, but the volume of edge cases suggests a human pass over the dns.ts restructuring is warranted before merge.

Other factors

  • All inline comments from me and CodeRabbit are resolved; the current bug-hunting pass found nothing.
  • The "resource" removal is a one-line, well-justified spec-conformance change and is independently revertable.
  • The musl build failures in CI appear to be infrastructure (a ci: retrigger commit was pushed) rather than caused by this change.
  • No CODEOWNERS entries match the touched paths.

@robobun

robobun commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-06-29, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main.

@robobun robobun closed this Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant