Add watchdog to prevent Chromium hanging
This commit is contained in:
parent
8d615a9966
commit
23ef48647f
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Reference in New Issue