[Issue 1446][Consumer] Fix consumer can't consume resent chunked messages#1464
Open
geniusjoe wants to merge 1 commit intoapache:masterfrom
Open
[Issue 1446][Consumer] Fix consumer can't consume resent chunked messages#1464geniusjoe wants to merge 1 commit intoapache:masterfrom
geniusjoe wants to merge 1 commit intoapache:masterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug where consumers could not consume chunked messages when chunks were resent due to reconnections or other failures. The fix aligns the Go client behavior with the Java client by properly handling duplicate chunks.
Changes:
- Enhanced chunk processing logic to detect and handle duplicate chunks (both corrupted and redelivered)
- Added proper cleanup of chunk message buffers to prevent memory leaks
- Added three new test cases to verify the fix works correctly for reconnection scenarios and duplicate chunk handling
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pulsar/consumer_partition.go | Implements duplicate chunk detection and handling logic; adds buffer cleanup calls to prevent memory leaks |
| pulsar/message_chunking_test.go | Adds comprehensive tests for chunk reconnection scenarios and duplicate chunk message handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2be1c8f to
2c96550
Compare
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.
Master Issue: #1446
related issue apache/pulsar#21070 and apache/pulsar#21101
Motivation
Current, when the producer resend the chunked message like this:
When the consumer received the M2, it will find that it's already tracking the UUID:0 chunked messages, and will then discard the message M1 and M2. This will lead to unable to consume the whole chunked message even though it's already persisted in the Pulsar topic.
Here is the code logic:
The bug can be easily reproduced using the testcase
TestChunkWithReconnectionandTestResendChunkMessagesintroduced by this PR.Modifications
The current chunk processing strategy is consistent with the behavior of the Java client:
https://github.com/apache/pulsar/blob/52a4d5ee84fad6af2736376a6fcdd1bc41e7c52f/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1579
When receiving the new duplicated first chunk of a chunked message, the consumer discard the current chunked message context and create a new context to track the following messages. For the case mentioned in Motivation, the M1 will be released and the consumer will assemble M2 and M3 as the chunked message.
Verifying this change
This change added tests and can be verified as follows:
TestChunkWithReconnectionTestResendChunkMessagesTestResendChunkWithAckHoleMessagesDoes this pull request potentially affect one of the following parts:
Documentation