fix(node/net): return string `family` in `server.address()`
Summary
Aligns Deno's Node.js compatibility layer (node:net, node:http, node:https,
node:http2, node:dns) with Node.js v18.4.0+ behavior by returning the family
property as a string ("IPv4" or "IPv6") rather than a number in server.address()
and socket address methods.
Node.js briefly changed family from string to number in v18.0.0 (nodejs/node#41431),
but reverted in v18.4.0 (nodejs/node#43054) due to ecosystem breakage
(nodejs/node#43014).
This fix ensures compatibility with npm packages that rely on the string format, which has been the stable API since Node.js v18.4.0.
Changes
- Modified
ext/node/polyfills/http.tsto addfamilyproperty toaddress()return - Modified
ext/node/polyfills/internal_binding/tcp_wrap.tsto return stringfamilyinstead of number ingetsockname(),getpeername(), and#connect() - Modified
ext/node/polyfills/net.tsto fixsocket.remoteFamilygetter (no longer needs conversion sincefamilyis now a string) - Modified
ext/node/polyfills/dns.tsandext/node/polyfills/internal/dns/promises.tsto accept string family values ("IPv4","IPv6") inlookup(), matching Node.js behavior - Added tests in
tests/unit_node/http_test.ts,tests/unit_node/http2_test.ts,tests/unit_node/https_test.ts,tests/unit_node/dns_test.ts, andtests/unit_node/net_test.ts
Node.js Compatibility Note
For non-IP addresses (when isIP() returns 0), the family property is undefined.
This matches Node.js C++ behavior in AddressToJS where family
is only set for AF_INET ("IPv4") and AF_INET6 ("IPv6"), and left undefined
otherwise.
Refs
- nodejs/node#43054
- nodejs/node@70b516e
Walkthrough
Adds export getIPFamily(ip) and uses it to represent IP family as string literals ("IPv4"/"IPv6") in TCP internals and AddressInfo.family in ext/node/polyfills/internal_binding/tcp_wrap.ts. ServerImpl.address() now returns { port, address, family } in ext/node/polyfills/http.ts. Socket.remoteFamily getter in ext/node/polyfills/net.ts was changed to return the raw numeric family. DNS lookup handling in ext/node/polyfills/dns.ts and ext/node/polyfills/internal/dns/promises.ts accepts string family values and maps them to numeric 4/6. New tests for http, http2, https, dns, and net validate family behavior.
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and specifically describes the main change: returning string family in server.address() for Node.js compatibility. |
| Description check | ✅ Passed | The description thoroughly explains the changeset, including context (Node.js version history), affected modules, and the rationale for the changes. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 69110070b948002e3167e8368d296814dc324e29 and 7a547109ad0adaf0a6e6bcf069bd1f26d00d8df1.
📒 Files selected for processing (2)
-
ext/node/polyfills/http.ts(2 hunks) -
ext/node/polyfills/internal/net.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- ext/node/polyfills/internal/net.ts
- ext/node/polyfills/http.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: test debug linux-aarch64
- GitHub Check: test debug linux-x86_64
- GitHub Check: test release linux-x86_64
- GitHub Check: test debug windows-x86_64
- GitHub Check: test debug macos-aarch64
- GitHub Check: test debug macos-x86_64
- GitHub Check: test release macos-aarch64
- GitHub Check: lint debug windows-x86_64
- GitHub Check: build libs
- GitHub Check: lint debug linux-x86_64
- GitHub Check: lint debug macos-x86_64
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Thanks for the review. Let me know if I should fix up the last commit, or anything else. I look forward to seeing this fix released— I've encountered this issue while trying to use the latest version of Playwright in a Deno web project.
Thanks, no action is needed from your side. In the meantime can do deno upgrade --canary if you'd like to try the fix.