fix: explicitly force DoH for Telegram and Discord domains
Browse files- Hugging Face Spaces' system DNS sinkholes these domains by returning a fake IP address instead of throwing ENOTFOUND.
- Because it returns a fake IP, the standard fallback logic in dns-fix.js was bypassed, causing n8n to connect to the sinkholed IP resulting in an ECONNRESET timeout after 60s.
- dns-fix.js now forces direct IP resolution via 1.1.1.1 DoH for these specific blocked hostnames before falling back to system DNS.
- dns-fix.js +48 -6
dns-fix.js
CHANGED
|
@@ -57,22 +57,64 @@ function dohResolve(hostname, callback) {
|
|
| 57 |
|
| 58 |
const origLookup = dns.lookup;
|
| 59 |
dns.lookup = function patchedLookup(hostname, options, callback) {
|
| 60 |
-
if (typeof options === "function") {
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
options = options || {};
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
return origLookup.call(dns, hostname, options, callback);
|
| 65 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
origLookup.call(dns, hostname, options, (err, address, family) => {
|
| 67 |
-
if (!err && address)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
if (err && (err.code === "ENOTFOUND" || err.code === "EAI_AGAIN")) {
|
| 69 |
console.error(`[DNS-FIX] Fallback DoH triggered for ${hostname}`);
|
| 70 |
dohResolve(hostname, (dohErr, ip) => {
|
| 71 |
-
if (dohErr || !ip)
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
callback(null, ip, 4);
|
| 74 |
});
|
| 75 |
} else {
|
|
|
|
| 76 |
callback(err, address, family);
|
| 77 |
}
|
| 78 |
});
|
|
|
|
| 57 |
|
| 58 |
const origLookup = dns.lookup;
|
| 59 |
dns.lookup = function patchedLookup(hostname, options, callback) {
|
| 60 |
+
if (typeof options === "function") {
|
| 61 |
+
callback = options;
|
| 62 |
+
options = {};
|
| 63 |
+
}
|
| 64 |
+
if (typeof options === "number") {
|
| 65 |
+
options = { family: options };
|
| 66 |
+
}
|
| 67 |
options = options || {};
|
| 68 |
+
|
| 69 |
+
if (
|
| 70 |
+
!hostname ||
|
| 71 |
+
hostname === "localhost" ||
|
| 72 |
+
hostname === "0.0.0.0" ||
|
| 73 |
+
hostname === "127.0.0.1" ||
|
| 74 |
+
hostname === "::1" ||
|
| 75 |
+
/^\d+\.\d+\.\d+\.\d+$/.test(hostname) ||
|
| 76 |
+
/^::/.test(hostname)
|
| 77 |
+
) {
|
| 78 |
return origLookup.call(dns, hostname, options, callback);
|
| 79 |
}
|
| 80 |
+
|
| 81 |
+
// FORCE DoH for known blocked domains on HF Spaces
|
| 82 |
+
const blockedDomains = ["api.telegram.org", "discord.com", "discordapp.com"];
|
| 83 |
+
const isBlocked = blockedDomains.some((d) => hostname === d || hostname.endsWith(`.${d}`));
|
| 84 |
+
|
| 85 |
+
if (isBlocked) {
|
| 86 |
+
console.error(`[DNS-FIX] Forcing DoH bypass for blocked domain: ${hostname}`);
|
| 87 |
+
return dohResolve(hostname, (dohErr, ip) => {
|
| 88 |
+
if (dohErr || !ip) {
|
| 89 |
+
return origLookup.call(dns, hostname, options, callback); // Last resort fallback
|
| 90 |
+
}
|
| 91 |
+
if (options.all) {
|
| 92 |
+
return callback(null, [{ address: ip, family: 4 }]);
|
| 93 |
+
}
|
| 94 |
+
callback(null, ip, 4);
|
| 95 |
+
});
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
// 1) Try system DNS first for everything else
|
| 99 |
origLookup.call(dns, hostname, options, (err, address, family) => {
|
| 100 |
+
if (!err && address) {
|
| 101 |
+
return callback(null, address, family);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// 2) System DNS failed with ENOTFOUND or EAI_AGAIN — fall back to DoH
|
| 105 |
if (err && (err.code === "ENOTFOUND" || err.code === "EAI_AGAIN")) {
|
| 106 |
console.error(`[DNS-FIX] Fallback DoH triggered for ${hostname}`);
|
| 107 |
dohResolve(hostname, (dohErr, ip) => {
|
| 108 |
+
if (dohErr || !ip) {
|
| 109 |
+
return callback(err); // Return original error
|
| 110 |
+
}
|
| 111 |
+
if (options.all) {
|
| 112 |
+
return callback(null, [{ address: ip, family: 4 }]);
|
| 113 |
+
}
|
| 114 |
callback(null, ip, 4);
|
| 115 |
});
|
| 116 |
} else {
|
| 117 |
+
// Other DNS errors — pass through
|
| 118 |
callback(err, address, family);
|
| 119 |
}
|
| 120 |
});
|