[ISSUE #S2] Guard against a missing ext unit in ConsumeQueue.estimateMessageCount - #11100
Open
zjncs wants to merge 1 commit into
Open
[ISSUE #S2] Guard against a missing ext unit in ConsumeQueue.estimateMessageCount#11100zjncs wants to merge 1 commit into
zjncs wants to merge 1 commit into
Conversation
…MessageCount estimateMessageCount unconditionally dereferences the ext unit when the consume queue ext is enabled. The stored tagsCode can legitimately be a raw value instead of an ext address (entries written while the ext was disabled, or persisted by the save-tagsCode-only fallback when the ext put fails), and ConsumeQueueExt.get returns null for such codes, so the consumer-lag estimation blows up with an NPE. Keep the raw tagsCode and let the filter handle the null ext unit, like the pull path already does. Signed-off-by: zjncs <18910855655@163.com>
RockteMQ-AI
approved these changes
Sep 9, 2026
RockteMQ-AI
left a comment
Contributor
There was a problem hiding this comment.
Summary
Correct NPE fix for a real production path — estimateMessageCount dereferences the ext unit unconditionally, but ConsumeQueueExt.get() returns null for raw tagsCodes in mixed-content states. The null-guard preserves the raw tagCode and passes null ext to the filter, matching how the rest of the codebase handles missing ext units. Test reproduces the exact mixed-content scenario.
Automated review by github-manager
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.
Motivation
ConsumeQueue.estimateMessageCountdereferences the ext unit unconditionally:The stored
tagsCodecan legitimately be a raw (positive) value rather than an ext address:putMessagePositionInfoWrapperwhenconsumeQueueExt.putfails (logged as "Save consume queue extend fail, So just save tagsCode").For a raw code
ConsumeQueueExt.getreturnsnull(it rejects non-ext addresses), soestimateMessageCountthrows an NPE. This path is live in production:DefaultMessageStore.estimateMessageCount→ConsumerLagCalculator(broker consumer-lag metrics with a filter).MessageFilter.isMatchedByConsumeQueuealready accepts a null ext unit ("message is before consumer"), so only this caller assumes non-null.Modifications
tagCodewhengetreturnsnulland pass the null ext to the filter, matching how the rest of the code treats a missing ext.Verification
Fail-before (new test on unpatched code):
The test writes one entry with the ext disabled (raw tagsCode persisted), re-enables the ext, then estimates the count — exactly the mixed-content state described above.
Pass-after: