Skip to content

feat: populate dnslookup timing with actual DNS resolution time#743

Merged
fengmk2 merged 7 commits intomasterfrom
copilot/fix-timing-dns-query
Apr 17, 2026
Merged

feat: populate dnslookup timing with actual DNS resolution time#743
fengmk2 merged 7 commits intomasterfrom
copilot/fix-timing-dns-query

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 12, 2026

  • Add kSocketDnsLookupTime symbol in src/symbols.ts
  • Capture DNS lookup time via net.client.socket diagnostics channel in src/diagnosticsChannel.ts
  • Calculate dnslookup timing in diagnosticsChannel.ts when first request is sent on socket
  • Update test/options.timing.test.ts to verify dnslookup timing is populated
  • Verify all existing tests pass (no regressions)
  • Replace Socket.prototype.emit monkey-patch with net.client.socket diagnostics channel subscription per reviewer feedback
  • Add timing fields documentation with text diagram to README
  • Fix README formatting (table alignment)
  • Move net.client.socket subscription into initDiagnosticsChannel() under init guard
  • Use explicit !== undefined check for kSocketDnsLookupTime (avoids false negative on timestamp 0)
  • Relax dnslookup > 0 to >= 0 to avoid flaky test on fast localhost DNS resolution

Copilot AI linked an issue Apr 12, 2026 that may be closed by this pull request
…ockets

Captures DNS lookup time via Socket.prototype.emit monkey-patch for the
'lookup' event. When the first request is sent on a socket, the DNS
lookup time is calculated relative to the request start time and stored
in the timing object.

Closes #577

Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/efde376e-b12f-42f6-9490-2ce39519fe7c

Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix timing differentiation for DNS query feat: populate dnslookup timing with actual DNS resolution time Apr 12, 2026
Copilot AI requested a review from fengmk2 April 12, 2026 12:20
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/node-modules/urllib@743

commit: b702864

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.65%. Comparing base (7fbbc0a) to head (b702864).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #743      +/-   ##
==========================================
+ Coverage   94.60%   94.65%   +0.05%     
==========================================
  Files          10       10              
  Lines         723      730       +7     
  Branches      226      228       +2     
==========================================
+ Hits          684      691       +7     
  Misses         36       36              
  Partials        3        3              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Apr 16, 2026

@copilot 只有这种 patch 方案吗?

….prototype.emit monkey-patch

Replace the global Socket.prototype.emit monkey-patch with a subscription
to Node.js's net.client.socket diagnostics channel. This channel fires
when a new TCP/IPC connection is initiated, giving us access to the socket
before the 'lookup' event fires, so we can attach a targeted per-socket
one-time listener instead of patching the global prototype.

Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/d5603429-8e76-46db-bd88-7a315ea660ba

Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot 只有这种 patch 方案吗?

已替换为更好的方案。不再 patch Socket.prototype.emit,改为订阅 Node.js 内置的 net.client.socket diagnostics channel,在 socket 创建时通过 socket.once('lookup', ...) 捕获 DNS 解析时间。commit 73cc285

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://registry.npmjs.org:80/urllib/latest
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js (http block)
  • registry.npmmirror.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Apr 16, 2026

@copilot 在 readme 增加一下 timing 字段的含义,并且通过文本图方式展示一下每个字段之间的关系,让用户可以一眼就能看懂。

@fengmk2 fengmk2 marked this pull request as ready for review April 16, 2026 14:21
Copilot AI review requested due to automatic review settings April 16, 2026 14:21
@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Apr 16, 2026

@codex review

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot 在 readme 增加一下 timing 字段的含义,并且通过文本图方式展示一下每个字段之间的关系,让用户可以一眼就能看懂。

已在 README 中添加 Timing 章节,包含文本图展示各字段在请求生命周期中的位置,以及每个字段的含义说明表格。commit 161c48e

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the Timing.dnslookup field meaningful by capturing DNS lookup completion time on new sockets and translating it into a request-relative timing value, with accompanying test assertions.

Changes:

  • Add a new socket symbol (kSocketDnsLookupTime) to store DNS lookup completion timestamps.
  • Subscribe to net.client.socket and attach a per-socket lookup listener to record performance.now(), then compute timing.dnslookup for the first request on a socket.
  • Extend timing tests to validate dnslookup behavior on first request vs. reused sockets.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/symbols.ts Adds a symbol used to stash DNS lookup timing data on sockets.
src/diagnosticsChannel.ts Captures DNS lookup completion time and computes timing.dnslookup on first request per socket.
test/options.timing.test.ts Adds assertions for dnslookup being set on first request and remaining 0 on socket reuse.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/diagnosticsChannel.ts Outdated
Comment thread src/diagnosticsChannel.ts
Comment thread test/options.timing.test.ts Outdated
@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Apr 16, 2026

…itDiagnosticsChannel, use explicit undefined check, relax dnslookup assertion

Agent-Logs-Url: https://github.com/node-modules/urllib/sessions/5980bc15-0896-428f-8709-7929c8055eb5

Co-authored-by: fengmk2 <156269+fengmk2@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 16, 2026

@copilot fix https://github.com/node-modules/urllib/actions/runs/24515689636/job/71659196403?pr=743

已修复。README 表格格式化问题已通过 vp check --fix 修正。同时根据 review 反馈:将 net.client.socket 订阅移入 initDiagnosticsChannel() 内(受 init guard 保护),改用 !== undefined 检查 kSocketDnsLookupTime,并将测试断言从 > 0 放宽为 >= 0 避免 localhost DNS 解析过快导致 flaky test。commit b702864

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://registry.npmjs.org:80/urllib/latest
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js (http block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js 3cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs (http block)
  • registry.npmmirror.com
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/urllib/urllib/node_modules/.pnpm/@voidzero-dev&#43;vite-plus-test@0.1.18_@arethetypeswrong&#43;core@0.18.2_@types&#43;node@22.19.15__60a1149b775ee6660f9a23cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/dist/workers/forks.js 3cab57a40ba/node_modules/@voidzero-dev/vite-plus-test/suppress-warnings.cjs (dns block)
  • viteplus.dev
    • Triggering command: /usr/bin/curl curl -fsSL REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented Apr 16, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fengmk2 fengmk2 merged commit 4c24cd6 into master Apr 17, 2026
19 checks passed
@fengmk2 fengmk2 deleted the copilot/fix-timing-dns-query branch April 17, 2026 00:50
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.

timing 需要区分一下 DNS 查询

3 participants