Spaces:
Runtime error
Runtime error
Update ultimate_fix.js
Browse files- ultimate_fix.js +18 -25
ultimate_fix.js
CHANGED
|
@@ -3,60 +3,53 @@ const tls = require('tls');
|
|
| 3 |
const http = require('http');
|
| 4 |
const https = require('https');
|
| 5 |
|
| 6 |
-
console.log(">>> [
|
| 7 |
|
| 8 |
-
//
|
| 9 |
-
// HF Spaces sometimes favor IPv6, but Discord's edge routing can drop those
|
| 10 |
-
// sockets mid-TLS-handshake. Force Node to always prefer IPv4.
|
| 11 |
dns.setDefaultResultOrder('ipv4first');
|
| 12 |
-
console.log(">>> [
|
| 13 |
|
| 14 |
-
// No-op since we are not hijacking DNS/IPs anymore
|
| 15 |
function rotateEndpoint() {
|
| 16 |
-
console.log(">>> [
|
| 17 |
}
|
| 18 |
|
| 19 |
-
//
|
| 20 |
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 21 |
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
|
| 22 |
-
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';
|
| 23 |
|
| 24 |
-
//
|
| 25 |
-
// Using fresh connections per request avoids stale/bad sockets on HF infra.
|
| 26 |
let dispatcher = null;
|
| 27 |
try {
|
| 28 |
const { setGlobalDispatcher, Agent } = require('undici');
|
| 29 |
|
| 30 |
dispatcher = new Agent({
|
| 31 |
connect: {
|
| 32 |
-
timeout:
|
| 33 |
rejectUnauthorized: false
|
| 34 |
},
|
| 35 |
-
keepAliveTimeout:
|
| 36 |
-
keepAliveMaxTimeout:
|
| 37 |
headersTimeout: 60000,
|
| 38 |
bodyTimeout: 60000,
|
| 39 |
-
pipelining:
|
| 40 |
-
maxRedirections: 5
|
| 41 |
-
connections: null // Unlimited connections (no pooling stale sockets)
|
| 42 |
});
|
| 43 |
|
| 44 |
setGlobalDispatcher(dispatcher);
|
| 45 |
global.fixedDispatcher = dispatcher;
|
| 46 |
-
console.log(">>> [
|
| 47 |
} catch (e) {
|
| 48 |
-
console.warn(">>> [
|
| 49 |
}
|
| 50 |
|
| 51 |
-
//
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
https.globalAgent = new https.Agent({ keepAlive: false, rejectUnauthorized: false });
|
| 55 |
|
| 56 |
-
console.log(">>> [
|
| 57 |
|
| 58 |
module.exports = {
|
| 59 |
dispatcher: dispatcher || global.fixedDispatcher || null,
|
| 60 |
-
wsAgent: null,
|
| 61 |
rotateEndpoint
|
| 62 |
};
|
|
|
|
| 3 |
const http = require('http');
|
| 4 |
const https = require('https');
|
| 5 |
|
| 6 |
+
console.log(">>> [NETWORK FIX] Booting network logic...");
|
| 7 |
|
| 8 |
+
// 1. Force IPv4 globally (Essential for Hugging Face container routing)
|
|
|
|
|
|
|
| 9 |
dns.setDefaultResultOrder('ipv4first');
|
| 10 |
+
console.log(">>> [NETWORK FIX] DNS forced to ipv4first.");
|
| 11 |
|
|
|
|
| 12 |
function rotateEndpoint() {
|
| 13 |
+
console.log(">>> [NETWORK FIX] rotateEndpoint called (no-op).");
|
| 14 |
}
|
| 15 |
|
| 16 |
+
// Ensure optimal TLS version constraints
|
| 17 |
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 18 |
tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
|
|
|
|
| 19 |
|
| 20 |
+
// 2. Stable Undici Agent configuration with proper connection pooling and realistic timeouts
|
|
|
|
| 21 |
let dispatcher = null;
|
| 22 |
try {
|
| 23 |
const { setGlobalDispatcher, Agent } = require('undici');
|
| 24 |
|
| 25 |
dispatcher = new Agent({
|
| 26 |
connect: {
|
| 27 |
+
timeout: 60000, // Allow up to 60s for slow handshakes on HF
|
| 28 |
rejectUnauthorized: false
|
| 29 |
},
|
| 30 |
+
keepAliveTimeout: 10000, // Keep active connections alive for 10 seconds
|
| 31 |
+
keepAliveMaxTimeout: 30000,
|
| 32 |
headersTimeout: 60000,
|
| 33 |
bodyTimeout: 60000,
|
| 34 |
+
pipelining: 1,
|
| 35 |
+
maxRedirections: 5
|
|
|
|
| 36 |
});
|
| 37 |
|
| 38 |
setGlobalDispatcher(dispatcher);
|
| 39 |
global.fixedDispatcher = dispatcher;
|
| 40 |
+
console.log(">>> [NETWORK FIX] Undici Dispatcher stabilized.");
|
| 41 |
} catch (e) {
|
| 42 |
+
console.warn(">>> [NETWORK FIX] Undici setup error:", e.message);
|
| 43 |
}
|
| 44 |
|
| 45 |
+
// 3. Fallback standard HTTPS/HTTP agents with standard keepAlive settings
|
| 46 |
+
http.globalAgent = new http.Agent({ keepAlive: true });
|
| 47 |
+
https.globalAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false });
|
|
|
|
| 48 |
|
| 49 |
+
console.log(">>> [NETWORK FIX] Network initialized successfully.");
|
| 50 |
|
| 51 |
module.exports = {
|
| 52 |
dispatcher: dispatcher || global.fixedDispatcher || null,
|
| 53 |
+
wsAgent: null,
|
| 54 |
rotateEndpoint
|
| 55 |
};
|