From 10d46519657973b32583bdf861c45a05b62b3fa9 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 22 May 2026 19:31:19 +0300 Subject: [PATCH] Sync update: 2026-05-22 19:31:19 --- whatsapp_bridge/server.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/whatsapp_bridge/server.js b/whatsapp_bridge/server.js index 66cc2ee..7e45e63 100644 --- a/whatsapp_bridge/server.js +++ b/whatsapp_bridge/server.js @@ -253,12 +253,35 @@ for (const p of possiblePaths) { } } +// ─── Clean Chrome Profile Locks ───────────────────────────────────────────── +function cleanChromeLocks(sessionPath) { + const lockFiles = [ + path.join(sessionPath, 'SingletonLock'), + path.join(sessionPath, 'Default', 'SingletonLock') + ]; + for (const lockFile of lockFiles) { + try { + if (fs.existsSync(lockFile)) { + console.log(`[CLEANUP] Removing dangling lock file: ${lockFile}`); + fs.unlinkSync(lockFile); + } + } catch (err) { + console.warn(`[CLEANUP WARNING] Could not remove lock file ${lockFile}:`, err.message); + } + } +} + // ─── Bootstrap Slot ──────────────────────────────────────────────────────── function bootstrapSlot(slotId) { if (slotId < 1 || slotId > 6) return; if (slots.has(slotId)) return slots.get(slotId); console.log(`[BOOTSTRAP] Initializing Slot ${slotId}...`); + + // Clean dangling lock files before launching Puppeteer + const sessionPath = path.join(__dirname, '.wwebjs_auth', `session-slot-${slotId}`); + cleanChromeLocks(sessionPath); + const { Client, LocalAuth } = require('whatsapp-web.js'); const client = new Client({ @@ -778,6 +801,8 @@ server.listen(PORT, async () => { if (!fs.existsSync(slot1SessionPath)) { for (const oldPath of oldSessionPaths) { if (fs.existsSync(oldPath)) { + // Clean lock files in the old session directory first + cleanChromeLocks(oldPath); console.log(`[MIGRATION] Migrating active WhatsApp session from ${oldPath} to Slot 1...`); try { if (fs.cpSync) { @@ -786,6 +811,8 @@ server.listen(PORT, async () => { const { execSync } = require('child_process'); execSync(`cp -R "${oldPath}" "${slot1SessionPath}"`); } + // Clean lock files in the new slot-1 session directory too + cleanChromeLocks(slot1SessionPath); console.log('[MIGRATION] Session migrated successfully! Slot 1 will load connected.'); break; } catch (migrationErr) {