Skip to content

fix: preserve DNS origin hostname on sockets#5577

Open
cyphercodes wants to merge 2 commits into
nodejs:mainfrom
cyphercodes:fix/dns-original-hostname-5573
Open

fix: preserve DNS origin hostname on sockets#5577
cyphercodes wants to merge 2 commits into
nodejs:mainfrom
cyphercodes:fix/dns-original-hostname-5573

Conversation

@cyphercodes

Copy link
Copy Markdown

This relates to...

Fixes #5573

Rationale

The DNS interceptor connects to a selected IP address, which causes Node's net.client.socket diagnostics channel to expose the IP as socket._host. Consumers can no longer correlate TCP connection timing with the original request hostname.

Changes

  • pass the request hostname through HTTP connection setup
  • connect to the interceptor-selected IP through a fixed lookup while preserving the logical hostname on the socket
  • add regression coverage for socket._host and remoteAddress

Features

N/A

Bug Fixes

  • preserve the original DNS hostname in HTTP socket diagnostics when the DNS interceptor selects an IP

Breaking Changes and Deprecations

N/A

Status

Testing:

  • node --test --test-name-pattern='#5573' test/interceptors/dns.js
  • npm run test:interceptors
  • npm run lint
  • npm run test:typescript

Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.48%. Comparing base (f36ea9c) to head (1036599).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
lib/core/connect.js 87.50% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5577   +/-   ##
=======================================
  Coverage   93.47%   93.48%           
=======================================
  Files         110      110           
  Lines       37564    37581   +17     
=======================================
+ Hits        35114    35132   +18     
+ Misses       2450     2449    -1     

☔ View full report in Codecov by Harness.
📢 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.

Signed-off-by: cyphercodes <cyphercodes@users.noreply.github.com>
@cyphercodes

Copy link
Copy Markdown
Author

Pushed a small test-only follow-up in 306602e to avoid relying on the net.client.socket diagnostics channel in the new DNS socket regression. The test now captures the socket/options through net.connect, which should avoid the Windows timeout while preserving the same assertions.

Verification run locally:

  • node --test test/interceptors/dns.js
  • npm run lint -- test/interceptors/dns.js
  • git diff --check

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.

Original hostname is lost for HTTP connections when using the DNS interceptor

3 participants