Skip to content

Commit 36b7f9d

Browse files
kt3kbartlomieju
authored andcommitted
Revert "fix(ext/node): fix dns.lookup result ordering (#26264)" (#26621)
This reverts commit d59599f. Closes #26588
1 parent 6f68793 commit 36b7f9d

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

ext/node/polyfills/http.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import { urlToHttpOptions } from "ext:deno_node/internal/url.ts";
5151
import { kEmptyObject } from "ext:deno_node/internal/util.mjs";
5252
import { constants, TCP } from "ext:deno_node/internal_binding/tcp_wrap.ts";
5353
import { notImplemented, warnNotImplemented } from "ext:deno_node/_utils.ts";
54-
import { isWindows } from "ext:deno_node/_util/os.ts";
5554
import {
5655
connResetException,
5756
ERR_HTTP_HEADERS_SENT,
@@ -1712,8 +1711,9 @@ export class ServerImpl extends EventEmitter {
17121711
port = options.port | 0;
17131712
}
17141713

1715-
// Use 0.0.0.0 for Windows, and [::] for other platforms.
1716-
let hostname = options.host ?? (isWindows ? "0.0.0.0" : "[::]");
1714+
// TODO(bnoordhuis) Node prefers [::] when host is omitted,
1715+
// we on the other hand default to 0.0.0.0.
1716+
let hostname = options.host ?? "0.0.0.0";
17171717
if (hostname == "localhost") {
17181718
hostname = "127.0.0.1";
17191719
}

ext/node/polyfills/internal/dns/utils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,20 @@ export function emitInvalidHostnameWarning(hostname: string) {
416416
);
417417
}
418418

419-
let dnsOrder = getOptionValue("--dns-result-order") || "verbatim";
419+
let dnsOrder = getOptionValue("--dns-result-order") || "ipv4first";
420420

421421
export function getDefaultVerbatim() {
422-
return dnsOrder !== "ipv4first";
422+
switch (dnsOrder) {
423+
case "verbatim": {
424+
return true;
425+
}
426+
case "ipv4first": {
427+
return false;
428+
}
429+
default: {
430+
return false;
431+
}
432+
}
423433
}
424434

425435
/**

ext/node/polyfills/internal_binding/cares_wrap.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,11 @@ export function getaddrinfo(
7575

7676
const recordTypes: ("A" | "AAAA")[] = [];
7777

78-
if (family === 6) {
79-
recordTypes.push("AAAA");
80-
} else if (family === 4) {
78+
if (family === 0 || family === 4) {
8179
recordTypes.push("A");
82-
} else if (family === 0 && hostname === "localhost") {
83-
// Ipv6 is preferred over Ipv4 for localhost
80+
}
81+
if (family === 0 || family === 6) {
8482
recordTypes.push("AAAA");
85-
recordTypes.push("A");
86-
} else if (family === 0) {
87-
// Only get Ipv4 addresses for the other hostnames
88-
// This simulates what `getaddrinfo` does when the family is not specified
89-
recordTypes.push("A");
9083
}
9184

9285
(async () => {

ext/node/polyfills/net.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,13 +1871,23 @@ function _setupListenHandle(
18711871

18721872
// Try to bind to the unspecified IPv6 address, see if IPv6 is available
18731873
if (!address && typeof fd !== "number") {
1874-
if (isWindows) {
1875-
address = DEFAULT_IPV4_ADDR;
1876-
addressType = 4;
1877-
} else {
1878-
address = DEFAULT_IPV6_ADDR;
1879-
addressType = 6;
1880-
}
1874+
// TODO(@bartlomieju): differs from Node which tries to bind to IPv6 first
1875+
// when no address is provided.
1876+
//
1877+
// Forcing IPv4 as a workaround for Deno not aligning with Node on
1878+
// implicit binding on Windows.
1879+
//
1880+
// REF: https://github.com/denoland/deno/issues/10762
1881+
// rval = _createServerHandle(DEFAULT_IPV6_ADDR, port, 6, fd, flags);
1882+
1883+
// if (typeof rval === "number") {
1884+
// rval = null;
1885+
address = DEFAULT_IPV4_ADDR;
1886+
addressType = 4;
1887+
// } else {
1888+
// address = DEFAULT_IPV6_ADDR;
1889+
// addressType = 6;
1890+
// }
18811891
}
18821892

18831893
if (rval === null) {

tests/unit_node/http_test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,10 @@ Deno.test("[node/http] IncomingRequest socket has remoteAddress + remotePort", a
322322
// deno-lint-ignore no-explicit-any
323323
const port = (server.address() as any).port;
324324
const res = await fetch(
325-
`http://localhost:${port}/`,
325+
`http://127.0.0.1:${port}/`,
326326
);
327327
await res.arrayBuffer();
328-
if (Deno.build.os === "windows") {
329-
assertEquals(remoteAddress, "127.0.0.1");
330-
} else {
331-
assertEquals(remoteAddress, "::1");
332-
}
328+
assertEquals(remoteAddress, "127.0.0.1");
333329
assertEquals(typeof remotePort, "number");
334330
server.close(() => resolve());
335331
});

tests/unit_node/tls_test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ for (
3232
) {
3333
Deno.test(`tls.connect sends correct ALPN: '${alpnServer}' + '${alpnClient}' = '${expected}'`, async () => {
3434
const listener = Deno.listenTls({
35-
hostname: "localhost",
3635
port: 0,
3736
key,
3837
cert,
3938
alpnProtocols: alpnServer,
4039
});
4140
const outgoing = tls.connect({
42-
host: "::1",
43-
servername: "localhost",
41+
host: "localhost",
4442
port: listener.addr.port,
4543
ALPNProtocols: alpnClient,
4644
secureContext: {
@@ -63,7 +61,6 @@ Deno.test("tls.connect makes tls connection", async () => {
6361
const ctl = new AbortController();
6462
let port;
6563
const serve = Deno.serve({
66-
hostname: "localhost",
6764
port: 0,
6865
key,
6966
cert,
@@ -74,8 +71,7 @@ Deno.test("tls.connect makes tls connection", async () => {
7471
await delay(200);
7572

7673
const conn = tls.connect({
77-
host: "::1",
78-
servername: "localhost",
74+
host: "localhost",
7975
port,
8076
secureContext: {
8177
ca: rootCaCert,
@@ -106,7 +102,6 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => {
106102
const { promise, resolve } = Promise.withResolvers<void>();
107103
const ctl = new AbortController();
108104
const serve = Deno.serve({
109-
hostname: "localhost",
110105
port: 8443,
111106
key,
112107
cert,
@@ -116,8 +111,7 @@ Deno.test("tls.connect mid-read tcp->tls upgrade", async () => {
116111
await delay(200);
117112

118113
const conn = tls.connect({
119-
host: "::1",
120-
servername: "localhost",
114+
host: "localhost",
121115
port: 8443,
122116
secureContext: {
123117
ca: rootCaCert,

0 commit comments

Comments
 (0)