-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipv4-preload.cjs
More file actions
44 lines (36 loc) · 1.27 KB
/
Copy pathipv4-preload.cjs
File metadata and controls
44 lines (36 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Preload script that forces dns.lookup to prefer IPv4.
// Loaded via NODE_OPTIONS=--require=<this file> before the Agent SDK cli.js starts.
//
// Works around a known undici bug where autoSelectFamily (RFC 8305) fails to
// fall back from IPv6 when EHOSTUNREACH is returned on networks with a
// Tailscale IPv6 ULA address but no routable IPv6 to Google's OAuth servers.
// See: https://github.com/nodejs/node/issues/48145
'use strict';
const dns = require('dns');
dns.setDefaultResultOrder('ipv4first');
const origLookup = dns.lookup;
dns.lookup = function patchedLookup(hostname, options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
if (typeof options === 'number') {
options = { family: options };
}
if (!options) options = {};
if (!options.family) {
options = { ...options, family: 4 };
}
return origLookup.call(dns, hostname, options, callback);
};
const origPromiseLookup = dns.promises.lookup;
dns.promises.lookup = function patchedPromiseLookup(hostname, options) {
if (typeof options === 'number') {
options = { family: options };
}
if (!options) options = {};
if (!options.family) {
options = { ...options, family: 4 };
}
return origPromiseLookup.call(dns.promises, hostname, options);
};