fix Client failed to withdraw the message #3257
Open
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.
🅰 Please add the issue ID after "Fixes #"
Fixes #3241
Problem Description
Users were unable to revoke messages, with the server returning error code 1004 (RecordNotFoundError) and the message "msg not found".
Investigation Process
Log Analysis:
Message sending and push operations were successful, with normal log records
During revocation attempts, the error "Error: 1004 RecordNotFoundError msg not found" was returned
Data Consistency Verification:
The conversation API query showed that the maximum sequence number (maxSeq) was 399
However, the message attempting to be revoked had a sequence number of 561
This indicated an inconsistency between database state and actually sent messages
Root Cause:
Messages were successfully sent and pushed to online users but failed to be persisted in MongoDB storage
The conversation sequence number records were not properly updated
When attempting to revoke, the system could not find the message record with the corresponding sequence number
Fix Solution
Design Approach
Implement a fault-tolerant mechanism that allows message revocation to proceed under specific conditions, even when the message record cannot be found.
Implementation Details
Modify the RevokeMsg method in internal/rpc/msg/revoke.go:
Instead of immediately returning an error when a message doesn't exist, implement a fallback strategy
Verify that the sequence number is within a reasonable range
Create a temporary message object for revocation notification
Log warnings but allow the operation to continue
Add Helper Function:
Implement getSessionTypeFromConversationID method to infer session type from conversation ID
Identify single chat or group chat types through prefixes (e.g., "sp_", "sg_")