diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2024-10-16 20:58:44 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-16 20:58:44 +0900 |
commit | d59599fc187c559ee231882773e1c5a2b932fc3d (patch) | |
tree | 3719d26bee7ce395afd28e4ab631dc5e63021327 /ext/node/polyfills/net.ts | |
parent | ea9c3ffaa240fc968832871000832eda1b92934a (diff) |
fix(ext/node): fix dns.lookup result ordering (#26264)
partially unblocks #25470
This PR aligns the resolution of `localhost` hostname to Node.js
behavior.
In Node.js `dns.lookup("localhost", (_, addr) => console.log(addr))`
prints ipv6 address `::1`, but it prints ipv4 address `127.0.0.1` in
Deno. That difference causes some errors in the work of enabling
`createConnection` option in `http.request` (#25470). This PR fixes the
issue by aligning `dns.lookup` behavior to Node.js.
This PR also changes the following behaviors (resolving TODOs):
- `http.createServer` now listens on ipv6 address `[::]` by default on
linux/mac
- `net.createServer` now listens on ipv6 address `[::]` by default on
linux/mac
These changes are also alignments to Node.js behaviors.
Diffstat (limited to 'ext/node/polyfills/net.ts')
-rw-r--r-- | ext/node/polyfills/net.ts | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/ext/node/polyfills/net.ts b/ext/node/polyfills/net.ts index 48e1d0de8..35d273be9 100644 --- a/ext/node/polyfills/net.ts +++ b/ext/node/polyfills/net.ts @@ -1871,23 +1871,13 @@ function _setupListenHandle( // Try to bind to the unspecified IPv6 address, see if IPv6 is available if (!address && typeof fd !== "number") { - // TODO(@bartlomieju): differs from Node which tries to bind to IPv6 first - // when no address is provided. - // - // Forcing IPv4 as a workaround for Deno not aligning with Node on - // implicit binding on Windows. - // - // REF: https://github.com/denoland/deno/issues/10762 - // rval = _createServerHandle(DEFAULT_IPV6_ADDR, port, 6, fd, flags); - - // if (typeof rval === "number") { - // rval = null; - address = DEFAULT_IPV4_ADDR; - addressType = 4; - // } else { - // address = DEFAULT_IPV6_ADDR; - // addressType = 6; - // } + if (isWindows) { + address = DEFAULT_IPV4_ADDR; + addressType = 4; + } else { + address = DEFAULT_IPV6_ADDR; + addressType = 6; + } } if (rval === null) { |