node icon indicating copy to clipboard operation
node copied to clipboard

dns: support IPv6-only and IPv4-only in setLocalAddress()

Open mohiuddin-khan-shiam opened this issue 7 months ago • 2 comments

What was fixed

Resolver.prototype.setLocalAddress(ipv4, ipv6) incorrectly required an IPv4 string even when callers only wanted to set an IPv6 local address.
Calling resolver.setLocalAddress(undefined, '::1') threw ERR_INVALID_ARG_TYPE, breaking the documented API and blocking IPv6-only use-cases.

Changes

  • lib/internal/dns/utils.js
    • Added ERR_MISSING_ARGS to imported error codes.
    • Re-implemented argument validation:
      • Now validates each address only when provided.
      • Throws ERR_MISSING_ARGS('ipv4','ipv6') when both arguments are omitted.
    • Keeps snapshot state logic unchanged.

Impact

Restores conformance with public documentation:

  • Users can bind a resolver to IPv6 only, IPv4 only, or both.
  • No breaking change for existing valid code; previously invalid calls now work as intended.

Refs: documentation for resolver.setLocalAddress

mohiuddin-khan-shiam avatar Jun 12 '25 21:06 mohiuddin-khan-shiam

Review requested:

  • [ ] @nodejs/net

nodejs-github-bot avatar Jun 12 '25 21:06 nodejs-github-bot

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 90.14%. Comparing base (bba07d7) to head (5858af6). Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58701      +/-   ##
==========================================
- Coverage   90.17%   90.14%   -0.03%     
==========================================
  Files         637      637              
  Lines      188023   188029       +6     
  Branches    36887    36889       +2     
==========================================
- Hits       169552   169505      -47     
- Misses      11223    11276      +53     
  Partials     7248     7248              
Files with missing lines Coverage Δ
lib/internal/dns/utils.js 99.45% <100.00%> (+<0.01%) :arrow_up:

... and 32 files with indirect coverage changes

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

codecov[bot] avatar Jun 14 '25 02:06 codecov[bot]