Merge pull request #2365 from FelipeFrancca/main

Bug Fix: QR Code Infinite Reconnection Loop
This commit is contained in:
Davidson Gomes
2026-02-24 12:09:15 -03:00
committed by GitHub
@@ -462,6 +462,16 @@ export class BaileysStartupService extends ChannelStartupService {
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
// FIX: Do not reconnect if it's the initial connection (waiting for QR code)
// This prevents infinite loop that blocks QR code generation
const isInitialConnection = !this.instance.wuid && (this.instance.qrcode?.count ?? 0) === 0;
if (isInitialConnection) {
this.logger.info('Initial connection closed, waiting for QR code generation...');
return;
}
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
this.logger.info({
@@ -478,6 +488,9 @@ export class BaileysStartupService extends ChannelStartupService {
await this.connectToWhatsapp(this.phoneNumber);
}, 3000);
} else {
this.logger.info(
`Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`,
);
this.sendDataWebhook(Events.STATUS_INSTANCE, {
instance: this.instance.name,
status: 'closed',