Improve disconnect reason handling for WhatsApp session stability#2367
Open
kobie3717 wants to merge 1 commit intoWhiskeySockets:masterfrom
Open
Improve disconnect reason handling for WhatsApp session stability#2367kobie3717 wants to merge 1 commit intoWhiskeySockets:masterfrom
kobie3717 wants to merge 1 commit intoWhiskeySockets:masterfrom
Conversation
- Add missing disconnect reason codes: methodNotAllowed (405), conflict (409), preconditionFailed (412) - Enhance CB:failure handler with proper error classification - Clear authentication state for terminal errors that indicate session corruption - Add detailed logging for unknown disconnect reasons - Prevent wasteful reconnection attempts on stale/corrupt sessions Fixes issues with Bad MAC / MessageCounterError after reconnection cycles by properly handling disconnect codes that indicate session state corruption. Related issues: WhiskeySockets#2340, WhiskeySockets#2321, WhiskeySockets#2362
Contributor
|
Thanks for opening this pull request and contributing to the project! The next step is for the maintainers to review your changes. If everything looks good, it will be approved and merged into the main branch. In the meantime, anyone in the community is encouraged to test this pull request and provide feedback. ✅ How to confirm it worksIf you’ve tested this PR, please comment below with: This helps us speed up the review and merge process. 📦 To test this PR locally:If you encounter any issues or have feedback, feel free to comment as well. |
This was referenced Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
This PR addresses disconnect reason handling issues that lead to Bad MAC / MessageCounterError after reconnection cycles when session state gets out of sync.
Root Cause
Changes Made
1. Extended DisconnectReason enum
methodNotAllowed = 405— indicates stale/corrupt sessionconflict = 409— session conflictpreconditionFailed = 412— session state mismatch2. Enhanced CB:failure handler in socket.ts
3. Session State Management
creds.me,creds.platform) for terminal errorsError Code Classifications
Impact