Skip to content

Commit b7aa2f2

Browse files
Merge pull request #2365 from FelipeFrancca/main
Bug Fix: QR Code Infinite Reconnection Loop
2 parents 550d35a + 00b42e2 commit b7aa2f2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,16 @@ export class BaileysStartupService extends ChannelStartupService {
462462

463463
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
464464
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
465+
466+
// FIX: Do not reconnect if it's the initial connection (waiting for QR code)
467+
// This prevents infinite loop that blocks QR code generation
468+
const isInitialConnection = !this.instance.wuid && (this.instance.qrcode?.count ?? 0) === 0;
469+
470+
if (isInitialConnection) {
471+
this.logger.info('Initial connection closed, waiting for QR code generation...');
472+
return;
473+
}
474+
465475
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
466476

467477
this.logger.info({
@@ -478,6 +488,9 @@ export class BaileysStartupService extends ChannelStartupService {
478488
await this.connectToWhatsapp(this.phoneNumber);
479489
}, 3000);
480490
} else {
491+
this.logger.info(
492+
`Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`,
493+
);
481494
this.sendDataWebhook(Events.STATUS_INSTANCE, {
482495
instance: this.instance.name,
483496
status: 'closed',

0 commit comments

Comments
 (0)