somratpro commited on
Commit
c1023d2
Β·
1 Parent(s): a126eae

fix: disable keep-alive on global HTTP/HTTPS agents to prevent ECONNRESET errors on Hugging Face Spaces

Browse files
Files changed (1) hide show
  1. dns-fix.js +10 -0
dns-fix.js CHANGED
@@ -14,8 +14,18 @@
14
  console.error("[DNS-FIX] dns-fix.js preload script loaded successfully.");
15
 
16
  const dns = require("dns");
 
17
  const https = require("https");
18
 
 
 
 
 
 
 
 
 
 
19
  // In-memory cache for runtime DoH resolutions
20
  const runtimeCache = new Map(); // hostname -> { ip, expiry }
21
 
 
14
  console.error("[DNS-FIX] dns-fix.js preload script loaded successfully.");
15
 
16
  const dns = require("dns");
17
+ 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