Spaces:
Runtime error
Runtime error
Update ultimate_fix.js
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768const tls = require('tls');const http = require('http');const https = require('https');console.log(">>> [ULTIMATE FIX] Booting standard dual-stack network logic...");// No-op since we are not hijacking DNS/IPs anymorefunction rotateEndpoint() {console.log(">>> [ULTIMATE FIX] rotateEndpoint called (DNS hijacking is disabled).");}// Keep standard TLS settings for compatibility, but don't reject unauthorized certs if neededtls.DEFAULT_MIN_VERSION = 'TLSv1.2';tls.DEFAULT_MAX_VERSION = 'TLSv1.3';tls.DEFAULT_CIPHERS = 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';// Force a fake Browser Identity globallyprocess.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36';let dispatcher = null;try {const { setGlobalDispatcher, Agent, ProxyAgent } = require('undici');const proxyUrl = process.env.DISCORD_PROXY || process.env.http_proxy || process.env.https_proxy;if (proxyUrl) {console.log(`>>> [ULTIMATE FIX] Proxy detected! Tunneling through: ${proxyUrl}`);dispatcher = new ProxyAgent({uri: proxyUrl.startsWith('http') ? proxyUrl : `http://${proxyUrl}`,token: 'Basic ' + Buffer.from('user:pass').toString('base64'),requestTimeout: 120000,connect: {timeout: 120000,rejectUnauthorized: false}});} else {dispatcher = new Agent({connect: {timeout: 30000,rejectUnauthorized: false// family: 4 is removed to allow dual-stack lookup},keepAliveTimeout: 60000,keepAliveMaxTimeout: 300000,headersTimeout: 60000,bodyTimeout: 60000,pipelining: 0,maxRedirections: 5});}setGlobalDispatcher(dispatcher);global.fixedDispatcher = dispatcher;console.log(`>>> [ULTIMATE FIX] Global Dispatcher active (${proxyUrl ? 'PROXY MODE' : 'STANDARD MODE'}).`);} catch (e) {console.warn(">>> [ULTIMATE FIX] Undici setup error:", e.message);}// Fix legacy http/https modules (family: 4 removed)http.globalAgent = new http.Agent({ keepAlive: true, keepAliveMsecs: 60000 });https.globalAgent = new https.Agent({ keepAlive: true, keepAliveMsecs: 60000, rejectUnauthorized: false });console.log(">>> [ULTIMATE FIX] Network system initialized with dual-stack (IPv4/IPv6) support.");module.exports = {dispatcher: dispatcher || global.fixedDispatcher || null,rotateEndpoint};1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162const dns = require('dns');const tls = require('tls');const http = require('http');const https = require('https');console.log(">>> [ULTIMATE FIX] Booting network logic...");// ─── FIX #2: Force IPv4 globally ───────────────────────────────────────────────// HF Spaces sometimes favor IPv6, but Discord's edge routing can drop those// sockets mid-TLS-handshake. Force Node to always prefer IPv4.dns.setDefaultResultOrder('ipv4first');console.log(">>> [ULTIMATE FIX] DNS forced to ipv4first.");// No-op since we are not hijacking DNS/IPs anymorefunction rotateEndpoint() {console.log(">>> [ULTIMATE FIX] rotateEndpoint called (no-op).");}// Keep standard TLS settings for compatibilitytls.DEFAULT_MIN_VERSION = 'TLSv1.2';tls.DEFAULT_MAX_VERSION = 'TLSv1.3';tls.DEFAULT_CIPHERS = 'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';// ─── FIX #3: Standard Undici Agent — no keep-alive, no pipelining ──────────────// Using fresh connections per request avoids stale/bad sockets on HF infra.let dispatcher = null;try {const { setGlobalDispatcher, Agent } = require('undici');dispatcher = new Agent({connect: {timeout: 30000,rejectUnauthorized: false},keepAliveTimeout: 0, // Disable keep-alive — fresh connection each timekeepAliveMaxTimeout: 0,headersTimeout: 60000,bodyTimeout: 60000,pipelining: 0, // No HTTP pipeliningmaxRedirections: 5,connections: null // Unlimited connections (no pooling stale sockets)});setGlobalDispatcher(dispatcher);global.fixedDispatcher = dispatcher;console.log(">>> [ULTIMATE FIX] Undici Dispatcher active (DIRECT, no keep-alive).");} catch (e) {console.warn(">>> [ULTIMATE FIX] Undici setup error:", e.message);}// ─── Standard HTTPS/HTTP agents (no keep-alive) ────────────────────────────────// Don't hold stale sockets open — let each request establish its own connection.http.globalAgent = new http.Agent({ keepAlive: false });https.globalAgent = new https.Agent({ keepAlive: false, rejectUnauthorized: false });console.log(">>> [ULTIMATE FIX] Network initialized. Mode: DIRECT (IPv4, no keep-alive).");module.exports = {dispatcher: dispatcher || global.fixedDispatcher || null,wsAgent: null, // Let discord.js use its default WebSocket agentrotateEndpoint};
ultimate_fix.js+34-40