Brozy123 commited on
Commit
7ee0f89
·
verified ·
1 Parent(s): 1fa89f0

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +21 -3
index.js CHANGED
@@ -1429,7 +1429,19 @@ async function initialize() {
1429
  server.startServer(client, commandsData);
1430
 
1431
  let retryCount = 0;
1432
- const maxRetryDelay = 60000; // 1 minute
 
 
 
 
 
 
 
 
 
 
 
 
1433
 
1434
  async function login() {
1435
  if (!TOKEN || TOKEN.length < 10) {
@@ -1439,7 +1451,7 @@ async function initialize() {
1439
 
1440
  try {
1441
  console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1})...`);
1442
- await client.login(TOKEN);
1443
  } catch (err) {
1444
  console.error(`[ERROR] Authentication Failed: ${err.message || 'No Description'}`);
1445
 
@@ -1448,11 +1460,17 @@ async function initialize() {
1448
  networkFix.rotateEndpoint();
1449
  }
1450
 
 
 
 
 
 
 
1451
  // Exponential backoff for retries
1452
  retryCount++;
1453
  const delay = Math.min(1000 * Math.pow(2, retryCount), maxRetryDelay);
1454
 
1455
- console.log(`[*] Retrying in ${delay / 1000}s with new route...`);
1456
  setTimeout(login, delay);
1457
  }
1458
  }
 
1429
  server.startServer(client, commandsData);
1430
 
1431
  let retryCount = 0;
1432
+ const maxRetryDelay = 15000; // keep retries fast
1433
+ const loginAttemptTimeoutMs = 20000;
1434
+ const hardRestartAfterMs = 90000;
1435
+ const startupAt = Date.now();
1436
+
1437
+ function withTimeout(promise, timeoutMs) {
1438
+ return Promise.race([
1439
+ promise,
1440
+ new Promise((_, reject) => {
1441
+ setTimeout(() => reject(new Error(`Login attempt timed out after ${timeoutMs}ms`)), timeoutMs);
1442
+ })
1443
+ ]);
1444
+ }
1445
 
1446
  async function login() {
1447
  if (!TOKEN || TOKEN.length < 10) {
 
1451
 
1452
  try {
1453
  console.log(`[*] Attempting connection to Discord (Attempt ${retryCount + 1})...`);
1454
+ await withTimeout(client.login(TOKEN), loginAttemptTimeoutMs);
1455
  } catch (err) {
1456
  console.error(`[ERROR] Authentication Failed: ${err.message || 'No Description'}`);
1457
 
 
1460
  networkFix.rotateEndpoint();
1461
  }
1462
 
1463
+ // If startup is stuck too long, restart quickly so HF can recover the container.
1464
+ if (Date.now() - startupAt >= hardRestartAfterMs) {
1465
+ console.error('[CRITICAL] Startup stuck too long, forcing restart...');
1466
+ process.exit(1);
1467
+ }
1468
+
1469
  // Exponential backoff for retries
1470
  retryCount++;
1471
  const delay = Math.min(1000 * Math.pow(2, retryCount), maxRetryDelay);
1472
 
1473
+ console.log(`[*] Retrying in ${delay / 1000}s...`);
1474
  setTimeout(login, delay);
1475
  }
1476
  }