Add watchdog to prevent Chromium hanging

This commit is contained in:
Deep Koluguri 2026-06-27 17:38:53 -04:00
parent 8d615a9966
commit 23ef48647f
1 changed files with 12 additions and 0 deletions

View File

@ -390,4 +390,16 @@ server.listen(PORT, '0.0.0.0', () => {
});
console.log('[WhatsApp Bot] Initializing client...');
// Watchdog Timer to prevent infinite Chromium loops (126% CPU bug)
const WATCHDOG_TIMEOUT_MS = 90000; // 90 seconds
let watchdog = setTimeout(() => {
console.error(`[WhatsApp Bot] 🚨 Watchdog triggered! Client failed to reach 'qr' or 'ready' state within ${WATCHDOG_TIMEOUT_MS / 1000} seconds. Exiting to allow Kubernetes restart.`);
process.exit(1);
}, WATCHDOG_TIMEOUT_MS);
// Clear the watchdog if it successfully generates a QR code or becomes ready
client.on('qr', () => { clearTimeout(watchdog); });
client.on('ready', () => { clearTimeout(watchdog); });
client.initialize();