mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2026-03-21 20:18:40 -06:00
Merge pull request #2365 from FelipeFrancca/main
Bug Fix: QR Code Infinite Reconnection Loop
This commit is contained in:
@@ -462,6 +462,16 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
|
|
||||||
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
|
const statusCode = (lastDisconnect?.error as Boom)?.output?.statusCode;
|
||||||
const codesToNotReconnect = [DisconnectReason.loggedOut, DisconnectReason.forbidden, 402, 406];
|
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);
|
const shouldReconnect = !codesToNotReconnect.includes(statusCode);
|
||||||
|
|
||||||
this.logger.info({
|
this.logger.info({
|
||||||
@@ -478,6 +488,9 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
await this.connectToWhatsapp(this.phoneNumber);
|
await this.connectToWhatsapp(this.phoneNumber);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
} else {
|
} else {
|
||||||
|
this.logger.info(
|
||||||
|
`Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`,
|
||||||
|
);
|
||||||
this.sendDataWebhook(Events.STATUS_INSTANCE, {
|
this.sendDataWebhook(Events.STATUS_INSTANCE, {
|
||||||
instance: this.instance.name,
|
instance: this.instance.name,
|
||||||
status: 'closed',
|
status: 'closed',
|
||||||
|
|||||||
Reference in New Issue
Block a user