From 3d253fff3ef2e7dacb27dae79acf7f0aed5ff216 Mon Sep 17 00:00:00 2001 From: "felipe.francca" Date: Fri, 16 Jan 2026 09:10:05 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20de=20bug:=20Loop=20infinit?= =?UTF-8?q?o=20de=20reconex=C3=A3o=20do=20c=C3=B3digo=20QR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/whatsapp/whatsapp.baileys.service.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts index 60e857fcc..8f941a2ec 100644 --- a/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts +++ b/src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts @@ -426,8 +426,19 @@ export class BaileysStartupService extends ChannelStartupService { if (connection === 'close') { const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode; const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406]; + + // FIX: Não reconectar se é primeira conexão (aguardando QR code) + // Isso evita loop infinito que impede geração do QR + const isInitialConnection = !this.instance.wuid && this.instance.qrcode.count === 0; + + if (isInitialConnection) { + this.logger.info('Initial connection closed, waiting for QR code generation...'); + return; + } + const shouldReconnect = !codesToNotReconnect.includes(statusCode); if (shouldReconnect) { + this.logger.warn(`Connection lost (status: ${statusCode}), reconnecting...`); await this.connectToWhatsapp(this.phoneNumber); } else { this.sendDataWebhook(Events.STATUS_INSTANCE, {