[Issue 1454][consumer] fix panic when messages size is 0#1460
[Issue 1454][consumer] fix panic when messages size is 0#1460unJASON wants to merge 3 commits intoapache:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request fixes a panic in the consumer when all messages in a batch are filtered/skipped, resulting in an empty message slice being sent to the dispatcher. The panic occurred in the dispatcher() function when trying to access the first element of an empty slice during queue clearing operations.
Changes:
- Added a check to prevent empty message slices from being sent to
queueChwhen all messages are filtered - Added a warning log when all messages in a batch are filtered
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(messages) == 0 { | ||
| pc.log.Warnf("receive %d messages , all filtered", numMsgs) | ||
| return nil | ||
| } |
There was a problem hiding this comment.
Consider adding a unit test to verify this edge case where all messages are filtered. The test should verify that when all messages in a batch are skipped (e.g., due to isDuplicate checks), the consumer doesn't panic and the skipped messages are properly accounted for in availablePermits. This would help prevent regressions of issue #1454.
RobertIndie
left a comment
There was a problem hiding this comment.
Could you help add a test?
|
I'm truly sorry, but I really don't have an ample amount of time at the moment. You see, it seems to me that the situation is quite evident. In fact, the modifications required are merely a few lines of code, which should be rather straightforward to rectify. |
1 similar comment
|
I'm truly sorry, but I really don't have an ample amount of time at the moment. You see, it seems to me that the situation is quite evident. In fact, the modifications required are merely a few lines of code, which should be rather straightforward to rectify. |
|
I've added the relevant test cases. |
(If this PR fixes a github issue, please add
Fixes #<xyz>.)Fixes #1454
(or if this PR is one task of a github issue, please add
Master Issue: #<xyz>to link to the master issue.)Master Issue: #1454
Motivation
Explain here the context, and why you're making that change. What is the problem you're trying to solve.
Modifications
Describe the modifications you've done.
if messages in
MessageReceivedare all skipped, then don't add intoqueuech.avoid panic when
dispatcher()received clear command fromclearQueueChVerifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If
yeswas chosen, please highlight the changesDocumentation