fix: resolve dns resolution issues by updating configuration in dns-fix.js
Browse files- dns-fix.js +24 -4
dns-fix.js
CHANGED
|
@@ -18,14 +18,34 @@ const http = require("http");
|
|
| 18 |
const https = require("https");
|
| 19 |
|
| 20 |
// ββ Keep-Alive Fix ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 21 |
-
// Node.js 22 changed the global HTTP/HTTPS agents to default keepAlive=true.
|
| 22 |
-
// On HF Spaces, the internal network proxy silently kills idle TCP sockets
|
| 23 |
-
// after ~60s. When n8n tries to reuse a stale socket it gets ECONNRESET.
|
| 24 |
-
// Disabling keep-alive forces a fresh TCP connection for every request.
|
| 25 |
http.globalAgent = new http.Agent({ keepAlive: false });
|
| 26 |
https.globalAgent = new https.Agent({ keepAlive: false });
|
| 27 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
// In-memory cache for runtime DoH resolutions
|
| 30 |
const runtimeCache = new Map(); // hostname -> { ip, expiry }
|
| 31 |
|
|
|
|
| 18 |
const https = require("https");
|
| 19 |
|
| 20 |
// ββ Keep-Alive Fix ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
http.globalAgent = new http.Agent({ keepAlive: false });
|
| 22 |
https.globalAgent = new https.Agent({ keepAlive: false });
|
| 23 |
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
|
| 25 |
+
// ββ TCP Connection Diagnostics ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
+
// Temporarily patch net.createConnection to log all outgoing TCP connections
|
| 27 |
+
// and their errors so we can identify the exact IP and failure mode.
|
| 28 |
+
const net = require("net");
|
| 29 |
+
const _origConnect = net.createConnection.bind(net);
|
| 30 |
+
net.createConnection = function (options, ...args) {
|
| 31 |
+
const host = options.host || options;
|
| 32 |
+
const port = options.port;
|
| 33 |
+
// Only log external connections (skip loopback)
|
| 34 |
+
if (host && host !== "127.0.0.1" && host !== "localhost" && host !== "::1") {
|
| 35 |
+
console.error(`[DNS-FIX] TCP connect β ${host}:${port}`);
|
| 36 |
+
const sock = _origConnect(options, ...args);
|
| 37 |
+
sock.on("connect", () =>
|
| 38 |
+
console.error(`[DNS-FIX] TCP connected β ${host}:${port}`),
|
| 39 |
+
);
|
| 40 |
+
sock.on("error", (err) =>
|
| 41 |
+
console.error(`[DNS-FIX] TCP error β ${host}:${port} β ${err.code}: ${err.message}`),
|
| 42 |
+
);
|
| 43 |
+
return sock;
|
| 44 |
+
}
|
| 45 |
+
return _origConnect(options, ...args);
|
| 46 |
+
};
|
| 47 |
+
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 48 |
+
|
| 49 |
// In-memory cache for runtime DoH resolutions
|
| 50 |
const runtimeCache = new Map(); // hostname -> { ip, expiry }
|
| 51 |
|