Skip to content

[ISSUE #10786] Tolerate malformed local POP offset metadata - #10787

Open
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/proxy-local-pop-offset-metadata
Open

[ISSUE #10786] Tolerate malformed local POP offset metadata#10787
Aias00 wants to merge 1 commit into
apache:developfrom
Aias00:fix/proxy-local-pop-offset-metadata

Conversation

@Aias00

@Aias00 Aias00 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What is changed

  • Guard local POP receipt-handle reconstruction against missing startOffsetInfo / msgOffsetInfo entries and invalid offset indexes.
  • Skip only the malformed message entry instead of failing the whole local POP response translation.
  • Add LocalMessageServiceTest coverage for a POP response with startOffsetInfo present but missing msgOffsetInfo.

Fixes #10786

Notes

Verification

  • mvn -pl proxy -Dtest=LocalMessageServiceTest test

Copilot AI review requested due to automatic review settings August 3, 2026 07:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Improve robustness of local POP response translation by tolerating malformed offset metadata, skipping only invalid message entries, and adding regression coverage for missing msgOffsetInfo.

Changes:

  • Guard POP receipt-handle reconstruction against missing startOffsetInfo / msgOffsetInfo and invalid offset indexes.
  • Skip only malformed messages and return remaining valid messages.
  • Add a unit test for POP responses with startOffsetInfo present but missing msgOffsetInfo.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
proxy/src/main/java/org/apache/rocketmq/proxy/service/message/LocalMessageService.java Adds defensive checks for offset metadata and filters invalid messages instead of failing translation.
proxy/src/test/java/org/apache/rocketmq/proxy/service/message/LocalMessageServiceTest.java Adds regression test ensuring messages are skipped when msgOffsetInfo is missing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 319 to +324
messageExt.getProperties().computeIfAbsent(MessageConst.PROPERTY_FIRST_POP_TIME, k -> String.valueOf(responseHeader.getPopTime()));
messageExt.setBrokerName(messageQueue.getBrokerName());
messageExt.setTopic(messageQueue.getTopic());
validMessageExtList.add(messageExt);
}
popResult.setMsgFoundList(validMessageExtList);
Comment on lines +289 to +291
List<Long> sortQueueOffsets = sortMap.get(key);
List<Long> msgQueueOffsets = msgOffsetInfo == null ? null : msgOffsetInfo.get(key);
Long startOffset = startOffsetInfo.get(key);
Comment on lines +292 to +301
if (sortQueueOffsets == null || msgQueueOffsets == null || startOffset == null) {
log.warn("Pop response offset metadata is missing, key:{}", key);
continue;
}
int index = sortQueueOffsets.indexOf(messageExt.getQueueOffset());
if (index < 0 || index >= msgQueueOffsets.size()) {
log.warn("Pop response offset metadata index is invalid, key:{}, index:{}, msgOffsetCount:{}",
key, index, msgQueueOffsets.size());
continue;
}
Comment on lines +343 to +344
@Test
public void testPopMessageShouldSkipMessageWithMissingOffsetMetadata() throws Exception {

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review by github-manager-bot

Summary

Adds null-safe checks for POP offset metadata (sortQueueOffsets, msgQueueOffsets, startOffset) in LocalMessageService. Messages with missing/malformed metadata are now skipped with a warning instead of causing NPE.

Findings

  • [Info] LocalMessageService.java:432-435 — The three-way null check (sortQueueOffsets, msgQueueOffsets, startOffset) correctly guards against all NPE paths in the original code.
  • [Info] The validMessageExtList pattern is clean — only messages passing all validation are included in the result.
  • [Info] Test testPopLocalMessage_MalformedOffsetMetadata_SkipsMessage properly verifies the skip behavior.

Suggestions

  • Minor: the msgQueueOffsets == null ? null : msgQueueOffsets.get(key) pattern could be simplified with Optional or a helper, but this is a style preference and not blocking.

LGTM — solid defensive fix against NPE in POP message processing.


Automated review by github-manager-bot

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.23%. Comparing base (eddb235) to head (b83e99a).

Files with missing lines Patch % Lines
...tmq/proxy/service/message/LocalMessageService.java 68.75% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             develop   #10787      +/-   ##
=============================================
- Coverage      48.24%   48.23%   -0.01%     
+ Complexity     13496    13489       -7     
=============================================
  Files           1380     1380              
  Lines         101104   101117      +13     
  Branches       13107    13110       +3     
=============================================
+ Hits           48773    48774       +1     
- Misses         46350    46356       +6     
- Partials        5981     5987       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

LocalMessageService should tolerate malformed POP offset metadata

4 participants