Skip to content

[Issue 1454][consumer] fix panic when messages size is 0#1460

Open
unJASON wants to merge 3 commits intoapache:masterfrom
unJASON:FIX1454
Open

[Issue 1454][consumer] fix panic when messages size is 0#1460
unJASON wants to merge 3 commits intoapache:masterfrom
unJASON:FIX1454

Conversation

@unJASON
Copy link

@unJASON unJASON commented Jan 22, 2026

(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 MessageReceived are all skipped, then don't add into queuech.

avoid panic when dispatcher() received clear command from clearQueueCh

Verifying this change

  • Make sure that the change passes the CI checks.

(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:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: don't know
  • The default values of configurations: no
  • The wire protocol: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 queueCh when 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.

Comment on lines +1440 to +1443
if len(messages) == 0 {
pc.log.Warnf("receive %d messages , all filtered", numMsgs)
return nil
}
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Member

@RobertIndie RobertIndie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help add a test?

@unJASON unJASON requested a review from RobertIndie February 2, 2026 00:59
@unJASON
Copy link
Author

unJASON commented Feb 2, 2026

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
@unJASON
Copy link
Author

unJASON commented Feb 2, 2026

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.

@crossoverJie
Copy link
Member

I've added the relevant test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] consumer panic if queueCh receive a message with size 0

4 participants