-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Pr 2365 #2379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Pr 2365 #2379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -426,10 +426,24 @@ 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: 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; | ||
|
Comment on lines
+432
to
+436
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (bug_risk): Early return on initial connection may skip other important close-handling logic (e.g., status notifications). Because this returns early when |
||
| } | ||
|
|
||
| const shouldReconnect = !codesToNotReconnect.includes(statusCode); | ||
| if (shouldReconnect) { | ||
| this.logger.warn(`Connection lost (status: ${statusCode}), reconnecting...`); | ||
| await this.connectToWhatsapp(this.phoneNumber); | ||
| } else { | ||
| this.logger.info( | ||
| `Skipping reconnection for status code ${statusCode} (code is in codesToNotReconnect list)`, | ||
| ); | ||
| this.sendDataWebhook(Events.STATUS_INSTANCE, { | ||
|
Comment on lines
426
to
447
|
||
| instance: this.instance.name, | ||
| status: 'closed', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition
(this.instance.qrcode?.count ?? 0) === 0only prevents reconnection when the connection closes before the first QR code is generated. However, based on the comment "Do not reconnect if it's the initial connection (waiting for QR code)", it appears the intent is to prevent reconnection during the entire QR code phase (count can be 1 to LIMIT while waiting for the user to scan). After the first QR code is generated (count becomes 1), if the connection closes, this check will fail and reconnection will still trigger, potentially causing the infinite loop mentioned in the comment. Consider using!this.instance.wuidalone (which indicates no authenticated user) or checking if count is below the LIMIT to cover all initial connection scenarios.